I'm familiar with LXC and wanted to try out docker. The issue I'm facing is that I can't find a way to just tell docker to start a container in the background, without executing a command. For example, with LXC I would do :
lxc create -t ubuntu -n my_container
lxc-start -n my_container -d
At this point I would have a running container I can use as any VM (ssh to it, install stuff in it ...) It seems that docker prevent this kind of usage. Am I missing something ?
As the operator (the person running a container from the image), you can override that CMD just by specifying a new COMMAND. If the image also specifies an ENTRYPOINT then the CMD or COMMAND get appended as arguments to the ENTRYPOINT. So to do what you want you need only specify a cmd, and override using /bin/bash .
You can then use the docker container start (or shorthand: docker start ) command to start the container at any point.
To run an image inside of a container, we use the docker run command. The docker run command requires one parameter and that is the image name. Let's start our image and make sure it is running correctly.
How to Use the docker run Command. The basic syntax for the command is: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] You can run containers from locally stored Docker images.
When I need to inspect a docker container that I've created that is having issues running the normal CMD in the Dockerfile, I comment out that command and replace with "sleep" command to just pause the container when it starts so I can log into it and inspect the installation.
In Dockerfile
CMD ["sleep","3600"]
To log into the running Docker instance
docker exec -i -t <Container ID> bash
With docker, from the CLI, you can't create a container without running a command on it. If you want to use the REST Api, you can call the 'create' endpoint without 'start'.
However, it wouldn't be any good for you I think.
In most case, you probably just want to run a container with bash docker run -t -i ubuntu bash
and do stuff there. Once you did everything you needed, you can simply commit and run from this point.
Usually however, it is better to do one step at a time in order to keep a clear history. Take a look at the Docker builder :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With