Professional Documents
Culture Documents
●
The recommended way to run the apache webserver docker (above) is
documented here : docker run d p 8181:80 <image_id>
● Go ahead and run the docker (we'll explain the d and p options in a bit – we
want a small win first)
– Choose a port that is free on the docker host (eg. 8181)
●
The command launches a running instance of the (webserver) image in a
docker container and returns a long long container id c3183f95.. (above)
Trouble-shooting
● Which users can run docker commands ?
– root, OR a user who can run the command as root (using sudo)
– A user belonging to thr 'docker' group
– Therefore, user 'techie' in this virtual lab can run docker commands(see picture below)
● Which users can start the docker service ?
– root, OR a user who can start the service as root (using sudo)
● Docker command returns error /var/run/docker.sock: no such file
– Most likely, docker daemon is not started (usually it should start on system boot)
– Start the docker service : sudo systemctl start docker
Trouble-shooting
● While pulling an image from docker hub, DNS lookup fails. The error message shown is
similar to the following :
Pulling repository centos
INFO[0000] Get
https://index.docker.io/v1/repositories/library/centos/images:
dial tcp: lookup index.docker.io: no DNS servers
– Add at least one of the following two entries to /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
and restart the network : sudo service network restart
● (Not applicable to this Virtual Lab) If you are behind a proxy, and trying to pull a docker
image from docker hub,
– Use HTTP_PROXY environment variable, for example :
sudo HTTP_PROXY=http://<proxy_host_ip>:<proxy_port> docker pull busybox
Take a Step Back
● Our docker image is a like a (lightweight) machine image with Apache web
server and all its dependencies installed
● The developer who published the image to DockerHub has inscribed
additional metadata into the image including
– what command to run when the image is launched (in this case, a suitable
command to start the webserver)
– On which port(s) a process running in the docker would listen, if any (in this case,
the webserver HTTP port – port 80)
● When you issue the docker run command, the docker daemon on your
docker host
– launches a RUNNING instance of the image in a docker container
– executes the command to run (the webserver), and
– exposes the container port (80) on which the running process (webserver) listens
Exposing a Container Port
● A docker is usually intended to run a server process available on the network
– Hence, a running container is assigned an IP address
● To find out the IP address of your running webserver docker, first find out its
container id : run docker ps
● The image and command fields help you identify the container you're looking for
● Next run docker inspect <container_id> and fish out the IPv4 address
from the command output :
"NetworkSettings": {
...
"IPAddress": "172.17.0.2"
Exposing a Container Port
●
So, one way of accessing the web server running in a docker is through its IP
address. From within your docker host, run
●
But, by default the IP address assigned to the docker is available only within
the docker host, on a private network created when the container is launched
● It is not available to the external world, and you may not even want to expose
a docker directly to the internet
●
So, docker allows you to map a port exposed by a container (80) to a specified
free port (8181) on the docker host using the option p 8181:80 passed to
docker run
– Now this will work :
Running A Docker in Background
● Let's revisit the -d flag to docker run command
● First stop the running webserver docker
– Run docker stop <container_id>
Remove container :
docker rm
This is a common sequence of steps, but
you may not need to use all of them. Delete image :
For syntax, use : docker <cmd> help docker rmi
Docker Lifecycle Commands
● Tips and Caveats :
– docker stop will stop a running container, but will not remove it. You
can restart the container using docker start <container_id>