Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch a container with Docker without specifying command

Tags:

docker

lxc

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 ?

like image 514
rmonjo Avatar asked Jun 30 '13 14:06

rmonjo


People also ask

How can I override CMD when running a docker image?

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 .

How do I start a container in docker?

You can then use the docker container start (or shorthand: docker start ) command to start the container at any point.

Which command can be used to start a docker container from an image?

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.

What is the command for launching docker container with terminal?

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.


2 Answers

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 
like image 174
GameSalutes Avatar answered Oct 12 '22 14:10

GameSalutes


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 :)

like image 23
creack Avatar answered Oct 12 '22 15:10

creack