Docker Command Line: Real-world QuestionSome 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 127.0.0.1:40180:80 -p 127.0.0.1:48000:8000 -p 45820:5820 -t -i user2/foo bash
Let's take each command line parameter in turn:
|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|
|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, 127.0.0.1.
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.
|Licensed under a Creative Commons Attribution 4.0 International License.|