How to keep the docker container up and running?

Here is my simple docker file

FROM java:8
EXPOSE 4000

now when I run it using the following command

  • Does the disk property size you define in Marathon include the size of the docker image?
  • Locally deploying a GCloud app with a custom Docker image
  • Docker workflow for development- running containers build up
  • Change Docker memory from the command line
  • import mysql data to kubernetes pod
  • Inspect mysql docker container over ssh tunnel
  • 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?

  • Could not access a running Docker Image of War (with tomcat) in minishift - OpenShift-Origin
  • docker hub webhook for _failed_ build?
  • Docker HaProxy exposed ports
  • How to make other microservices aware of the IP address of the consul for service registry
  • Install + start ssh in dockerfile derived from official jenkins docker image
  • Certificate error when pulling docker images
  • 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

    https://docs.docker.com/engine/reference/builder/#cmd

    and

    https://docs.docker.com/engine/reference/builder/#entrypoint

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