Docker Tutorial

author: Frank

Getting Started

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
sudo yum install -y yum-utils;

sudo yum-config-manager \
    --add-repo \;
sudo yum install docker-ce docker-ce-cli;

Take out sudo

sudo groupadd docker;
sudo usermod -aG docker $USER;
sudo restart

Launch Docker Deamon

sudo systemctl enable --now docker.service;

lesson 1

docker run hello-world;
docker ps -a;
docker stop {CID};
docker rm {CID};

docker –help docker info docker logs {CID} docker images

lesson 2


docker run --rm -p 80:80 httpd
docker run --rm -d --name httpd01 -p 80:80 httpd
docker exec -it httpd01 bash
echo '<html><body><h1>Docker works!</h1></body></html>' > /usr/local/apache2/htdocs/index.html
docker stop httpd01
docker rm httpd01

-p Publish 在port of OS對應到port of container self

lesson 3


mkdir html;
echo '<html><head><title>GG</title></head><body><h1>Docker is work.</h1></body></html>' > ./html/index.html;
docker run --rm --name httpd01 -p 80:80 -v "$PWD"/html:/usr/local/apache2/htdocs/ httpd

lesson 4


docker volume create --name workspace;
docker run --rm -d --name httpd01 -p 80:80 -v workspace:/usr/local/apache2/htdocs/ httpd
docker run --rm -it --name developer -v workspace:/root ubuntu bash

docker stop httpd01

lesson 5


docker network create net-mysql

docker run --rm -d --name simple-mysql -e MYSQL_ROOT_PASSWORD=root --network net-mysql mysql:5.7.25

docker run --rm -d --name simple-phpmyadmin -e PMA_HOST=simple-mysql -p 80:80 --network net-mysql phpmyadmin/phpmyadmin:latest

docker ps -a;

docker stop simple-mysql simple-phpmyadmin;
docker network rm net-mysql

lesson 6


// none
docker run --rm -it --name test --net=none busybox
// brige
docker run --rm -it --name test --net=bridge busybox
// host
docker run --rm -it --name test --net=host busybox

//container tty1
docker run --rm -it --name test busybox

docker exec -it test

//container tty2
docker run --rm -it --name test01 --net=container:test busybox

docker exec -it test01

lesson 7

exec & attach

docker run -dit --name gg busybox

docker exec -it gg sh
->ps aux

docker attach gg
->ps aux

docker start gg
docker attach gg

exit & “Ctrl p + Ctrl q”

lesson 8

Dockerfile (simple)

mkdir myproject && cd myproject
echo "hello" > hello
echo -e "FROM busybox\nCOPY /hello /\nRUN cat /hello" > Dockerfile
docker build -t helloapp:v1 .

Thank you for listening.