Docker
November 1, 2020

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

docker rmi $(docker images -q)

Tags and Versioning

1. Tagging and Versioning

2. Using Tags

Website

FROM nginx:1.15.2-alpine

User service api

FROM node:14.15.0-alpine

3. Running Containers Using Tags

Remove runing containers

docker rm -f website
docker rm -f user-service

Run images

docker run --name user-service -d -p 3000:3000 user-service:lates

docker run --name website -d -p 80:80 website:latest

4. Tagging Override

Changed it)

FROM nginx:1-alpine

Building image

docker build -t website:latest .

5. Tagging Images

Building adab

docker build -t adab-website:latest .

PS D:\other\docker\rock-site> docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
website             latest              c3d091a4e119        5 minutes ago       28.5MB
adab-website        latest              c3d091a4e119        5 minutes ago       28.5MB
user-service        latest              21d41e5937a9        37 minutes ago      153MB
<none>              <none>              fae4ae77b4b0        40 minutes ago      25.4MB
<none>              <none>              9edc54b53c01        About an hour ago   153MB
<none>              <none>              741e3cb45f61        About an hour ago   28.5MB
<none>              <none>              c0f914ef8443        3 days ago          979MB
node                alpine              1e8b781248bb        9 days ago          115MB
nginx               alpine              4efb29ff172a        10 days ago         21.8MB
nginx               latest              f35646e83998        2 weeks ago         133MB

Add new tag image
PS D:\other\docker\rock-site> docker tag adab-website:latest adab-website:1

PS D:\other\docker\rock-site> docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
adab-website        1                   c3d091a4e119        6 minutes ago       28.5MB
adab-website        latest              c3d091a4e119        6 minutes ago       28.5MB
website             latest              c3d091a4e119        6 minutes ago       28.5MB
user-service        latest              21d41e5937a9        38 minutes ago      153MB
<none>              <none>              fae4ae77b4b0        41 minutes ago      25.4MB
<none>              <none>              9edc54b53c01        About an hour ago   153MB
<none>              <none>              741e3cb45f61        About an hour ago   28.5MB
<none>              <none>              c0f914ef8443        3 days ago          979MB
node                alpine              1e8b781248bb        9 days ago          115MB
nginx               alpine              4efb29ff172a        10 days ago         21.8MB
nginx               latest              f35646e83998        2 weeks ago         133MB

We can create version 2

We'll change something and then:

  1. docker build -t adab-website:latest .
  2. docker tag adab-website:latest adab-website:2
  3. (we can see version 2)

PS D:\other\docker\rock-site> docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
adab-website 2 960ed70c7a7e 39 seconds ago 28.5MB
adab-website latest 960ed70c7a7e 39 seconds ago 28.5MB
adab-website 1 c3d091a4e119 13 minutes ago 28.5MB
website latest c3d091a4e119 13 minutes ago 28.5MB
user-service latest 21d41e5937a9 46 minutes ago 153MB
<none> <none> fae4ae77b4b0 48 minutes ago 25.4MB
<none> <none> 9edc54b53c01 About an hour ago 153MB
<none> <none> 741e3cb45f61 About an hour ago 28.5MB
<none> <none> c0f914ef8443 3 days ago 979MB
node alpine 1e8b781248bb 9 days ago 115MB
nginx alpine 4efb29ff172a 10 days ago 21.8MB
nginx latest f35646e83998 2 weeks ago 133MB
PS D:\other\docker\rock-site>

6. Running Container Using Tags

Runing container the latest tag:

docker run --name website-latest -p 8080:80 -d adab-website:latest

Runing container the 1 vesion:

docker run --name website-1 -p 8081:80 -d adab-website:1

Runing container the 2 version:

docker run --name website-2 -p 8082:80 -d adab-website:2

And we can see them:

D:\other\docker\rock-site>docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a6cf9efda795 adab-website:2 "/docker-entrypoint.…" 3 seconds ago Up 2 seconds 0.0.0.0:8082->80/tcp website-2 99f714cc15bd adab-website:1 "/docker-entrypoint.…" 4 minutes ago Up 4 minutes 0.0.0.0:8081->80/tcp website-1 5f063c826579 adab-website:latest "/docker-entrypoint.…" 5 minutes ago Up 5 minutes 0.0.0.0:8080->80/tcp website-latest

It's the second (a new) version, port 8082

It's the fist (an old) version, port 8081

After stop container, need to do this command:

docker start website-2

docker start website-1

Docker Registries

1. Docker Registries

Docekr registry is a simply thing:)

  1. Hihly scalable several side application that stores and lets you distribute Docker images.
  2. Used in your CD/CI Pipeline
  3. Run you applications

Docker Registry

We have private and public docker registries
  • Docker HUB
  • quay.io
  • Amazon ECR

2. Docker Hub

Need to sign in here: https://hub.docker.com/

and create repsoitory, for example adab-ui

3. Pushing Images to Docker Hub

docker ps

We see adab-website:1 and adab-website:2

Need to do:

docker tag adab-website:1 shamil8/adab-ui:1

docker tag adab-website:2 shamil8/adab-ui:2

docker tag adab-website:latest shamil8/adab-ui:latest

Then after, do it:

docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
postgres 9.6-alpine 5116b8393895 2 weeks ago 36.5MB
rabbitmq management d4489446dfcc 3 weeks ago 203MB
adab-website 2 960ed70c7a7e 4 weeks ago 28.5MB
adab-website latest 960ed70c7a7e 4 weeks ago 28.5MB
shamil8/adab-ui 2 960ed70c7a7e 4 weeks ago 28.5MB shamil8/adab-ui latest 960ed70c7a7e 4 weeks ago 28.5MB
website latest c3d091a4e119 4 weeks ago 28.5MB
shamil8/adab-ui 1 c3d091a4e119 4 weeks ago 28.5MB
adab-website 1 c3d091a4e119 4 weeks ago 28.5MB
user-service latest 21d41e5937a9 4 weeks ago 153MB
node alpine 1e8b781248bb 5 weeks ago 115MB
nginx alpine 4efb29ff172a 5 weeks ago 21.8MB
nginx latest f35646e83998 6 weeks ago 133MB
deeppavlov/base-cpu latest 8854a6c9669a 5 months ago 799MB

Need to login in docker:

docker login

After:

docker push shamil8/adab-ui:1

docker push shamil8/adab-ui:2

docker push shamil8/adab-ui:latest

Success!

4. Pulling Images From Registry

First of all, we need to remove local repository if we have that:

docker rmi shamil8/adab-ui:1

docker rmi shamil8/adab-ui:2

docker rmi shamil8/adab-ui:latest

Pull that repository, :latesttag)

docker pull shamil8/adab-ui

Runing adab-ui an image

docker run --name adab-ui -p 9000:80 -d shamil8/adab-ui

in docker brain:)

"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "9000"
}
]
},

Debugging Containers

1. Docker Inspect

Bunching information about this container

docker inspect user-service

2. Docker Logs

docker logs user-service
Example app listening at http://localhost:3000

it's from Express js in index.js file

PS D:\docker\rock-site> docker logs adab-ui
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
172.17.0.1 - - [30/Nov/2020:10:36:01 +0000] "GET / HTTP/1.1" 200 4671 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36" "-"
172.17.0.1 - - [30/Nov/2020:10:36:01 +0000] "GET /vendor/bootstrap/css/bootstrap.min.css HTTP/1.1" 200 160403 "http://localhost:9000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36" "-"
172.17.0.1 - - [30/Nov/2020:10:36:01 +0000] "GET /css/one-page-wonder.min.css HTTP/1.1" 200 2524 "http://localhost:9000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36" "-"
172.17.0.1 - - [30/Nov/2020:10:36:01 +0000] "GET /vendor/jquery/jquery.min.js HTTP/1.1" 200 89476 "http://localhost:9000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36" "-"
172.17.0.1 - - [30/Nov/2020:10:36:01 +0000] "GET /vendor/bootstrap/js/bootstrap.bundle.min.js HTTP/1.1" 200 81084 "http://localhost:9000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36" "-"
172.17.0.1 - - [30/Nov/2020:10:36:01 +0000] "GET /img/01.jpg HTTP/1.1" 200 547797 "http://localhost:9000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36" "-"
172.17.0.1 - - [30/Nov/2020:10:36:01 +0000] "GET /img/02.jpg HTTP/1.1" 200 252376 "http://localhost:9000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36" "-"
172.17.0.1 - - [30/Nov/2020:10:36:01 +0000] "GET /img/03.jpg HTTP/1.1" 200 535000 "http://localhost:9000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36" "-"
2020/11/30 10:36:02 [error] 29#29: *5 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost:9000", referrer: "http://localhost:9000/"
172.17.0.1 - - [30/Nov/2020:10:36:02 +0000] "GET /favicon.ico HTTP/1.1" 404 555 "http://localhost:9000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36" "-"
172.17.0.1 - - [30/Nov/2020:10:36:49 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36" "-"

docker logs -f (it means to follow) adab-ui

docker logs --help

3. Docker exec

First of all, we need to check inspect command, see bash pathЖ

"Cmd": [
"/bin/sh",
"-c",
"node index.js"
],

and then:

docker exec -it user-service /bin/sh

Yeep, Thank you!