Docker
October 28, 2020

Part 1/3 Docker Tutorial for Beginners | Full Course [2020]

Intro

#check docekr status (ls -l)
docker ps

Install nginx

docker pull nginx

Show images

docker images
D:\other\docker\docker-learn>docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mystack             latest              af0d710af187        10 days ago         943MB
nginx               latest              f35646e83998        2 weeks ago         133MB

Running Container

Actualy running a container

docker run nginx:latest

Show containers

docker container ls 

We see nginx:laterst container

D:\other\docker\docker-learn>docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
113260347dd3        nginx:latest        "/docker-entrypoint.…"   3 minutes ago       Up 3 minutes        80/tcp              mystifying_bardeen

Run docekr in the backround

docker run -d nginx:latest

Exposing ports (Открытие портов)

Stop container

docker stop [container_ID or daemon_NAME]

We can start nginx in the port 8080

docker run -d -p 8080:80 nginx:latest

and we see...

Welcome to nginx!

We can run nginx in the port 3000 :)

docker run -d -p 3000:80 nginx:latest

Success!!!

Exposing multiple ports

Exposin multiple ports

Two ports for nginx

docker run -d -p 3000:80 -p 8080:80 nginx:latest

It's amazing)

Managing containers

docker stop [containerID or daemon name]

Show all docker containers (We see all)

docker ps -a

Remove container

docker rm [containerID or deamon_NAME]

We also can remove all containers so

Need to open PowerShell and then:

docker rm @(docker ps -aq)  -f (force - it means: remove even throw working)

in ubuntu

docker rm $(docker ps -aq) -f (force - it means: remove even throw working)

Container with name in docker

Adab Nginx name in docker (adab_nginx )

docker run --name adab_nginx -d -p 3000:80 -p 8080:80 nginx:latest

docker PS

docker ps --format="ID\t{{.ID}}\nNAME\t{{.Names}}\nImage\t{{.Image}}\nPORTS\t{{.Ports}}\nCOMMAND\t{{.Command}}\nCREATED\t{{.CreatedAt}}\nSTATUS\t{{.Status}}\n"

We see new format

ID fa9136dbad07
NAME website_test
Image nginx:latest
PORTS 0.0.0.0:9000->80/tcp
COMMAND "/docker-entrypoint.…"
CREATED 2020-10-28 18:11:09 +0700 +07
STATUS Up 3 minutes
ID 9691c8f8f307
NAME adab_nginx
Image nginx:latest
PORTS 0.0.0.0:3000->80/tcp, 0.0.0.0:8080->80/tcp
COMMAND "/docker-entrypoint.…"
CREATED 2020-10-28 18:06:19 +0700 +07
STATUS Up 6 minutes

In Mac OS

export FORMAT="ID\t{{.ID}}\nNAME\t{{.Names}}\nImage\t{{.Image}}\nPORTS\t{{.Ports}}\nCOMMAND\t{{.Command}}\nCREATED\t{{.CreatedAt}}\nSTATUS\t{{.Status}}\n"

if we want that we can call it so (we created variable for it)

docker ps --format=$FORMAT

Docker volumes (объемы)

Docker volumes in nginx

In Windows

docker run --name website -v ${pwd}:/usr/share/nginx/html:ro -d -p 8080:80 nginx

In MacOS

docker run --name website -v $(pwd) -d -p 8080:80 nginx

Bash container

docker exec -it website bash

open nginx directory:

cd /usr/share/nginx/html/

We can create a file if we have rule for it! (without :ro)

docker run --name website -v ${pwd}:/usr/share/nginx/html -d -p 8080:80

touch about.html

Customize website (настроить)

We can use these websites

https://startbootstrap.com/themes/landing-pages/

I chose it)

https://github.com/StartBootstrap/startbootstrap-one-page-wonder

and add in that directory!

Sharing Volumes Between Containers

Copy docker container

docker run --name website-copy --volumes-from website -d -p 8081:80 nginx

How to remove old Docker containers

Removing old docker containers

docker container prune

This will remove all stopped containers and should work on all platforms the same way.