April 09, 2017

Docker Command Line: Real-world Question

Docker Command Line: Real-world Question

Some time ago a user posted this question on the Google Docker Group. He had inherited a Docker platform and wanted to know what the following command line did:

$ sudo docker run -v /home/user1/foo:/home/user2/src -v /projects/foo:/home/user2/data  \
-p -p -p 45820:5820 -t -i user2/foo bash

Let's take each command line parameter in turn:

Parameter Description
sudo used to run docker as the super user if not previously setup
docker run docker run command
-v <host path>:<container path> maps a host volume into a container
-p <hostIP>:<hostPORT>:<containerPORT> binds a container port to a host port from a specific host IP
-p <hostPORT>:<containerPORT> binds a container port to a host port from any host IP
-t attaches a terminal to the container
-i enables interactive mode
user2/foo image identifier
bash container startup command

The main command, docker run, starts a container from the image, user2/foo and runs the bash executable in the container. Persistent data (-v) is enabled by mounting the host directory, /projects/foo, as a mount point /home/user2/data inside the container.

The container exposes three container ports 80, 8000, 5820 as host mounts 40180, 48000, 45820 respectively (-p). Additionally container ports 80 and 48000 can only be access on the host via local interface,

Finally -i and -t are used to enable interactive access to the standard input and output of the container, i.e. you can enter commands directly at the keyboard and see the output on the terminal.

Note: The back-slash (\) at the end of the line is a continuation mark. It tells the Linux Shell that the command line continues on the next line; it joins the two lines together as one contiguous command line.


No comments:

Post a Comment