Don’t stop now! The next scenario will only take about 10 minutes to complete.

Docker 101

Step 1 of 2

Docker CLI

Containers

docker run -ti alpine

exit

docker run -d httpd:alpine

docker ps

docker ps -a

docker run -d --name http1 httpd:alpine

docker ps

docker exec -ti http1 /bin/sh

exit

docker stop http1

docker ps

docker start http1

docker ps

docker stop http1 && docker rm http1

docker ps -aq

docker rm -f $(docker ps -aq)

Networking

docker network ls

docker network inspect bridge

docker run -d --name http1 httpd:alpine

docker exec -ti http1 wget -qO- localhost:80

docker inspect http1

docker exec -ti http1 ifconfig

From other container

(they should be in the same docker network. Default is bridge)

docker run -ti alpine wget -qO- 172.18.0.2:80

docker run -ti --link http1 alpine wget -qO- http1:80

docker run -ti --link http1:server alpine wget -qO- server:80

From host

wget -qO- 172.18.0.2:80

External access

  • Port mapping

docker run -d --name http2 -p 8000:80 httpd:alpine wget -qO- localhost:8000

  • Host network

docker run -d --name http3 --network host httpd:alpine

wget -qO- localhost:80

docker rm -f $(docker ps -aq)


Volumes

docker volume mount

docker run -d --name http1 -p 8000:80 -v vol1:/usr/local/apache2/htdocs/ httpd:alpine

wget -qO- localhost:8000

docker run -it --rm -v vol1:/vol alpine sh -c 'echo "modified content" >/vol/index.html'

docker run -it --rm -v vol1:/vol alpine ls -l /vol

wget -qO- localhost:8000

docker rm -f http1

docker run -d --name http1 -p 8000:80 -v vol1:/usr/local/apache2/htdocs/ httpd:alpine

wget -qO- localhost:8000

host bind mount

docker run -d --name http_spider -p 8001:80 -v $PWD/vol_spider:/usr/local/apache2/htdocs/ httpd:alpine

wget -qO- localhost:8001

docker run -d --name http_bat -p 8002:80 -v $PWD/vol_bat:/usr/local/apache2/htdocs/ httpd:alpine

wget -qO- localhost:8002