Thursday, August 25, 2022

Docker Training

 1)Docker Introduction and Architecture  - Done

2)Docker Installation and Docker Info  - Done

3)Create First Container, List Container, Remove Container

 Create: docker container run --name=kishor -d nginx  

 # docker container ls

 #docker ps

#docker ps -a

 #docker container ls -a

[root@ip-172-31-39-133 ~]# docker container stop d13851e2b5fb

d13851e2b5fb

[root@ip-172-31-39-133 ~]# docker container rm d13851e2b5fb

d13851e2b5fb

  


4)Create Container in background, stop, start, detach  container.

[root@ip-172-31-39-133 ~]# docker container run -d httpd

d85bfc54941ec18d2ec4380e9098989ff23872843cc39862bd09389e984ff60c

[root@ip-172-31-39-133 ~]# docke rps

-bash: docke: command not found

[root@ip-172-31-39-133 ~]# docker ps

'CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS     NAMES

d85bfc54941e   httpd     "httpd-foreground"       4 seconds ago    Up 4 seconds    80/tcp    intelligent_satoshi


5)Docker Container Inspect

docker inspect d85bfc54941e|less


6)Whats going on inside the container

#docker logs d85bfc54941e 


7)Docker port mapping, rename container, restart the container, exec container

[root@ip-172-31-39-133 ~]# docker run -d -p 3306:80 nginx

ba313210c37b5a4193d92317a2734087555072e1c614eec80185708fd6fce98b

[root@ip-172-31-39-133 ~]# docker ps

CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS        PORTS                                   NAMES

ba313210c37b   nginx     "/docker-entrypoint.…"   2 seconds ago   Up 1 second   0.0.0.0:3306->80/tcp, :::3306->80/tcp   musing_poitras


8)Attach to a running container, kill, wait, pause, unpause, prune, port



[root@ip-172-31-39-133 ~]# docker rm $(docker ps -a -f status=exited -q)

351171d12678

d6e05ed3325b

ab0bcc80a5f3    

[root@ip-172-31-39-133 ~]# docker ps -a

CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

[root@ip-172-31-39-133 ~]#

[root@ip-172-31-39-133 ~]# docker rmi $(docker images -a -q)

9)Create docker container, diff docker container and copy file into container.


10)Export/Import Docker Container.

 #docker container ls

  #docker container export 351171d12678 > my_ubuntu.tar

  #ls -l

  #docker image import my_ubuntu.tar my_ubunut

  #docker images

  #docker container run -it my_ubunut

  #docker container run -it my_ubunut /bin/bash


11)How to create docker image from a running container.

[root@ip-172-31-39-133 ~]# docker container commit --author "Kishor Aswar" -m "THis is my Customized image"  351171d12678 my_con_image

sha256:e8f2927cc89c7c2de6828369e1f0c3107a6a017814abf075a444f873818c540c

[root@ip-172-31-39-133 ~]# docker images

REPOSITORY     TAG       IMAGE ID       CREATED         SIZE

my_con_image   latest    e8f2927cc89c   7 seconds ago   114MB

[root@ip-172-31-39-133 ~]# docker run -it my_con_image /bin/bash

root@7b5ba6313bee:/#


12)How to push image on docker hub, image tag, image pull, docker login.

https://hub.docker.com/

[root@ip-172-31-39-133 ~]# docker pull nginx:1.23

1.23: Pulling from library/nginx

7a6db449b51b: Pull complete

ca1981974b58: Pull complete

d4019c921e20: Pull complete

7cb804d746d4: Pull complete

e7a561826262: Pull complete

7247f6e5c182: Pull complete

Digest: sha256:b95a99feebf7797479e0c5eb5ec0bdfa5d9f504bc94da550c2f58e839ea6914f

Status: Downloaded newer image for nginx:1.23

docker.io/library/nginx:1.23

[root@ip-172-31-39-133 ~]# docker images

REPOSITORY   TAG       IMAGE ID       CREATED      SIZE

nginx        1.23      2b7d6430f78d   5 days ago   142MB

[root@ip-172-31-39-133 ~]#

[root@ip-172-31-39-133 ~]# docker images

REPOSITORY   TAG       IMAGE ID       CREATED       SIZE

nginx        1.23      2b7d6430f78d   5 days ago    142MB

ubuntu       latest    df5de72bdb3b   3 weeks ago   77.8MB

[root@ip-172-31-39-133 ~]# docker image tag ubuntu kishoraswar/ubuntu_new

[root@ip-172-31-39-133 ~]# docker image push

"docker image push" requires exactly 1 argument.

See 'docker image push --help'.


Usage:  docker image push [OPTIONS] NAME[:TAG]


Push an image or a repository to a registry

[root@ip-172-31-39-133 ~]# docker images

REPOSITORY               TAG       IMAGE ID       CREATED       SIZE

nginx                    1.23      2b7d6430f78d   5 days ago    142MB

kishoraswar/ubuntu_new   latest    df5de72bdb3b   3 weeks ago   77.8MB

ubuntu                   latest    df5de72bdb3b   3 weeks ago   77.8MB

[root@ip-172-31-39-133 ~]# docker image push  kishoraswar/ubuntu_new

Using default tag: latest

The push refers to repository [docker.io/kishoraswar/ubuntu_new]

629d9dbab5ed: Mounted from library/ubuntu

latest: digest: sha256:42ba2dfce475de1113d55602d40af18415897167d47c2045ec7b6d9746ff148f size: 529

[root@ip-172-31-39-133 ~]#



[root@ip-172-31-39-133 ~]# docker login

Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.

Username: kishoraswar

Password:

WARNING! Your password will be stored unencrypted in /root/.docker/config.json.

Configure a credential helper to remove this warning. See

https://docs.docker.com/engine/reference/commandline/login/#credentials-store


Login Succeeded


  # docker images
  # docker tag ubuntu:latest kishoraswar/myrepo:myubuntutag
  # docker push kishoraswar/myrepo:myubuntutag

13)How to inspect, list and history of docker image.

[root@ip-172-31-39-133 ~]# docker image history df5de72bdb3b

IMAGE          CREATED       CREATED BY                                      SIZE      COMMENT

df5de72bdb3b   3 weeks ago   /bin/sh -c #(nop)  CMD ["bash"]                 0B

<missing>      3 weeks ago   /bin/sh -c #(nop) ADD file:396eeb65c8d737180…   77.8MB

[root@ip-172-31-39-133 ~]#

docker image inspect df5de72bdb3b

15)Layered architecture and Dockerfile

[root@ip-172-31-39-133 ~]# cat Dockerfile

FROM ubuntu

MAINTAINER Kishor Aswar

USER root

RUN apt-get update -y

RUN apt-get install tree -y

RUN touch /tmp/file1

RUN touch /tmp/file2


[root@ip-172-31-39-133 ~]# vi Dockerfile

[root@ip-172-31-39-133 ~]# docker build -t myos:3.0 .

Sending build context to Docker daemon  116.4MB

Step 1/7 : FROM ubuntu

 ---> df5de72bdb3b

Step 2/7 : MAINTAINER Kishor Aswar

 ---> Using cache

 ---> c9e9b6a1ef5a

Step 3/7 : USER root

 ---> Using cache

 ---> db9cf470d44a

Step 4/7 : RUN apt-get update -y

 ---> Using cache

 ---> 400b74a03009

Step 5/7 : RUN apt-get install tree -y

 ---> Using cache

 ---> d5f601900dde

Step 6/7 : RUN touch /tmp/file1

 ---> Running in 0e7ead191ce1

Removing intermediate container 0e7ead191ce1

 ---> ba71d11f5172

Step 7/7 : RUN touch /tmp/file2

 ---> Running in 3da57cf7a554

Removing intermediate container 3da57cf7a554

 ---> 33bb176bdbdf

Successfully built 33bb176bdbdf

Successfully tagged myos:3.0

[root@ip-172-31-39-133 ~]# docker images -a

REPOSITORY   TAG       IMAGE ID       CREATED          SIZE

myos         3.0       33bb176bdbdf   9 seconds ago    115MB

<none>       <none>    ba71d11f5172   10 seconds ago   115MB

myos         2.0       d5f601900dde   6 minutes ago    115MB

<none>       <none>    400b74a03009   6 minutes ago    114MB

<none>       <none>    db9cf470d44a   7 minutes ago    77.8MB

myos         1.0       c9e9b6a1ef5a   14 minutes ago   77.8MB

nginx        latest    2b7d6430f78d   6 days ago       142MB

httpd        latest    a981c8992512   6 days ago       145MB

ubuntu       latest    df5de72bdb3b   3 weeks ago      77.8MB

centos       latest    5d0da3dc9764   11 months ago    231MB

[root@ip-172-31-39-133 ~]#


16)Dockerfile(Label , RUN, ENV, Workdir)




17)Dockerfile(ADD, COPY, USER)

18)Dockerfile(CMD)

19)Dockerfile(Expose and create a SSH container using dockerfile)


20)Dockerfile(ENTRYPOINT)

Docker difference between run, cmd, entrypoint commands (til.codes)

  • RUN executes command(s) in a new layer and creates a new image. E.g., it is often used for installing software packages.
  • CMD sets default command and/or parameters, which can be overwritten from command line when docker container runs.
  • ENTRYPOINT configures a container to run as an executable. This is usually the file path to the executable inside the container.

Use RUN instructions to build your image by adding layers on top of initial image.

Prefer ENTRYPOINT to CMD when building executable Docker image and you need a command always to be executed. Additionally use CMD if you need to provide extra default arguments that could be overwritten from command line when docker container runs.

Choose CMD if you need to provide a default command and/or arguments that can be overwritten from command line when docker container runs.

21)Docker Volume(Docker Storage), mysql data persist in docker container

22)Docker Volume Creation

23)Docker volume(Remove, Prune)

24)Docker Bind Mount

25)Docker networking(Bridge, Host, Null)

26)Docker Network(Connect, Disconnect)

27)Docker network(Remove, Prune)

28)Docker Registry/Repository(Insecure)

29)Docker Registry With Basic Authentication)


Docker Compose/swarm


Kubernetes



No comments:

Post a Comment

Sample Game App Deployment on EKS cluster

 https://padmakshi.medium.com/setting-up-an-eks-cluster-and-deploying-a-game-application-a-step-by-step-guide-08790e0be117