How to keep the docker container up and running?

Here is my simple docker file

FROM java:8

now when I run it using the following command

  • How do I use Liblas in python in docker without error?
  • Docker API: cpu_stats vs percpu_stats
  • Docker: Mysql crashes after few seconds when it has been started
  • Docker oracle database fails when starting after commiting
  • Upgrade docker container to latest image
  • Cache gems in GitLab CI bundle build
  • sudo docker run --name hello dockerfile

    and do docker ps -a it shows the status as exited. I just want to keep this container up and running so I can ssh into this container and probably transfer files and so on. It looks like containers are mainly used to run servers am I correct?

  • Some questions about Docker version and module versions
  • Concourse Pipeline failing for simple pipleline
  • Running docker containers inside of docker + mesos + marathon
  • What is different of Config and ContainerConfig of docker inspect?
  • Docker --env-file - executable file not found in $PATH
  • empty PATH returned when entering new Docker image
  • 2 Solutions collect form web for “How to keep the docker container up and running?”

    That is realy simple.
    Because your container is running nothing that last long. What happens is, that this container starts, has nothing to do and stops.

    What you can do is:

    1. Run the container in interactive mode with attached tty. This way your console enters the container after it’s start, and let him run a tty, which is something to do and prevends the container from stopping. Then you can work inside this container, like installing an application. Doing this your work will be lost after stoping the container. But you can run docker commit on that container, which makes your changes persistent.

    docker run -i -t –name hello dockerfile

    1. Enhance your dockerfile with something usefull. Like copying an application into the container and provide a CMD command to run, when the container starts.
      After this the container will last as long as your CMD command runs. If the command is a server or deamon application, the container will last for ever and will only stop when you stop him.

    you can at least keep your container up with something like docker run -d hello sleep infinity but as said by René M, you should put in your Dockerfile something to do in your CMD or ENTRYPOINT, see the doc


    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.