Saturday, 13 June 2020

Docker - Notes

Debugging:

If docker is not starting then run the command "dockerd" in terminal, it will show the logs in the terminal.

Settings are present in /etc/docker. There will be two json key.json and daemon.json.

If docker container failed with exit (1) then check "docker logs <container_id>"

 

Docker Postgres

infra1@master-node[~] $ sudo docker run -d -p8001:5432 -e POSTGRES_PASSWORD=postgres -v /home/infra1/postgres/data:/var/lib/postgresql/data artifactory.global.com/postgres:alpine

 sudo docker run -d --name mysql_for_pydio -e MYSQL_ROOT_PASSWORD=password  artifactory.global.com/mysql

To get inside the container:

infra1@master-node[~] $ docker exec -it 942102da94c0 /bin/bash

 

 

 

 

 

Pluralsight getting started:

 

To get version. Docker installation consists of server, API and client. Client is the CLI which we use and server is core engine. API calls were made to server whenever we run a command from Docker CLI.

root@academy-rhel7[axessuser] # docker version

Client:

 Version:         1.12.6

 API version:     1.24

 Package version: docker-common-1.12.6-11.el7.x86_64

 Go version:      go1.7.4

 Git commit:      96d83a5/1.12.6

 Built:           Thu Feb 23 11:52:33 2017

 OS/Arch:         linux/amd64

 

Server:

 Version:         1.12.6

 API version:     1.24

 Package version: docker-common-1.12.6-11.el7.x86_64

 Go version:      go1.7.4

 Git commit:      96d83a5/1.12.6

 Built:           Thu Feb 23 11:52:33 2017

 OS/Arch:         linux/amd64

 

Info commands show the containers running.

root@academy-rhel7[axessuser] # docker info

Containers: 0

 Running: 0

 Paused: 0

 Stopped: 0

Images: 0

Server Version: 1.12.6

Storage Driver: devicemapper

 Pool Name: rootvg-docker--pool

 Pool Blocksize: 524.3 kB

 Base Device Size: 10.74 GB

 Backing Filesystem: xfs

 Data file:

 Metadata file:

 Data Space Used: 20.45 MB

 Data Space Total: 7.68 GB

 Data Space Available: 7.659 GB

 Metadata Space Used: 40.96 kB

 Metadata Space Total: 54.53 MB

 Metadata Space Available: 54.48 MB

 Thin Pool Minimum Free Space: 767.6 MB

 Udev Sync Supported: true

 Deferred Removal Enabled: true

 Deferred Deletion Enabled: false

 Deferred Deleted Device Count: 0

 Library Version: 1.02.135-RHEL7 (2016-11-16)

Logging Driver: journald

Cgroup Driver: systemd

Plugins:

 Volume: local

 Network: bridge host overlay null

 Authorization: rhel-push-plugin

Swarm: inactive

Runtimes: docker-runc runc

Default Runtime: docker-runc

Security Options: seccomp selinux

Kernel Version: 3.10.0-514.26.1.el7.x86_64

Operating System: Red Hat Enterprise Linux Server 7.2 (Maipo)

OSType: linux

Architecture: x86_64

Number of Docker Hooks: 2

CPUs: 2

Total Memory: 1.796 GiB

Name: academy-rhel7.localdomain

ID: J6CQ:RQHG:2JKT:IKNU:L5BQ:7DQD:OT3T:ZALJ:KA55:PKEN:2T3S:GGSS

Docker Root Dir: /var/lib/docker

Debug Mode (client): false

Debug Mode (server): false

Registry: https://artifactory.global.com/v1/

WARNING: bridge-nf-call-iptables is disabled

WARNING: bridge-nf-call-ip6tables is disabled

Insecure Registries:

 docker-registry-default.apps.dtp-np.ocp.com

 172.30.0.0/16

 127.0.0.0/8

Registries: artifactory.global.com (secure), docker.io (secure)

 

Run command is used to start docker process. Without any option to run command it will login to the container and execute the script. In below case the image is not present locally so the Docker server automatically pulled from Artifactory

root@academy-rhel7[axessuser] # docker run hello-world

Unable to find image 'hello-world:latest' locally

Trying to pull repository artifactory.global.com/hello-world ..

latest: Pulling from artifactory.global.com/hello-world

1b930d010525: Pull complete

Digest: sha256:4fe721ccc2e8dc7362278a29dc660d833570ec2682f4e4194f4ee23e415e1064

 

Hello from Docker!

This message shows that your installation appears to be working correctly.

 

To generate this message, Docker took the following steps:

 1. The Docker client contacted the Docker daemon.

 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.

    (amd64)

 3. The Docker daemon created a new container from that image which runs the

    executable that produces the output you are currently reading.

 4. The Docker daemon streamed that output to the Docker client, which sent it

    to your terminal.

 

To try something more ambitious, you can run an Ubuntu container with:

 $ docker run -it ubuntu bash

 

Share images, automate workflows, and more with a free Docker ID:

 https://hub.docker.com/

 

For more examples and ideas, visit:

 https://docs.docker.com/get-started/

 

 

PS command with "a" option will show historical process that were stopped

root@academy-rhel7[axessuser] # docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES

0c8a7e686341        hello-world         "/hello"            2 minutes ago       Exited (0) 2 minutes ago                       amazing_knuth

 

PS  command will show only the running process

root@academy-rhel7[axessuser] # docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

 

Image command shows the list of image we have in local

root@academy-rhel7[axessuser] # docker images

REPOSITORY                                             TAG                 IMAGE ID            CREATED             SIZE

artifactory.global.com/hello-world   latest              fce289e99eb9        11 months ago       1.84 kB

 

Pull command will pull the image from Artifactory (link registered in registry)

root@academy-rhel7[axessuser] # docker pull alpine

Using default tag: latest

Trying to pull repository artifactory.global.com/alpine ..

latest: Pulling from artifactory.global.com/alpine

89d9c30c1d48: Pull complete

Digest: sha256:c19173c5ada610a5989151111163d28a67368362762534d8a8121ce95cf2bd5a

root@academy-rhel7[axessuser] # docker pull ubuntu

Using default tag: latest

Trying to pull repository artifactory.global.com/ubuntu ..

latest: Pulling from artifactory.global.com/ubuntu

7ddbc47eeb70: Pull complete

c1bbdc448b72: Pull complete

8c3b70e39044: Pull complete

45d437916d57: Pull complete

Digest: sha256:7c2e0528340e055e5b6d959d70a71a0a6932bd4de56385718d8e15c2295cd5a2

 

We can pull specific version using :<version number>

root@academy-rhel7[axessuser] # docker pull ubuntu:14.04

Trying to pull repository artifactory.global.com/ubuntu ..

14.04: Pulling from artifactory.global.com/ubuntu

a7344f52cb74: Pull complete

515c9bb51536: Pull complete

e1eabe0537eb: Pull complete

4701f1215c13: Pull complete

Digest: sha256:3590458403b522985068fa21888da3e351e5c72833936757c33baf9555b09e1e

 

Image command shows the list of image we have in local

root@academy-rhel7[axessuser] # docker images

REPOSITORY                                             TAG                 IMAGE ID            CREATED             SIZE

artifactory.global.com/ubuntu        latest              775349758637        6 weeks ago         64.19 MB

artifactory.global.com/alpine        latest              965ea09ff2eb        8 weeks ago         5.548 MB

artifactory.global.com/ubuntu        14.04               2c5e00d77a67        7 months ago        188.2 MB

artifactory.global.com/hello-world   latest              fce289e99eb9        11 months ago       1.84 kB

root@academy-rhel7[axessuser] # docker rmi ubuntu:14.04

Untagged: ubuntu:14.04

Untagged: artifactory.global.com/ubuntu@sha256:3590458403b522985068fa21888da3e351e5c72833936757c33baf9555b09e1e

Deleted: sha256:2c5e00d77a67934d5e39493477f262b878f127b9c01b491f06d8f06f78819578

Deleted: sha256:664a2bb343be8b1a691e0ce9c563ee654c30a1c694dc1b25ebb5467fa3d074fd

Deleted: sha256:4ac0c5a114c714b429ff471f5415974618e0b6fc743070d445cd0e2ac586cc7b

Deleted: sha256:5f200444c0009c41eb39bc1cf37a5b3c2e953478f2f373c5a1873dee820e0ced

Deleted: sha256:b057ab380990c219581e3b074919413ebe31079cbd0d615f63872c471b4dc633

 

root@academy-rhel7[axessuser] # docker images

REPOSITORY                                             TAG                 IMAGE ID            CREATED             SIZE

artifactory.global.com/ubuntu        latest              775349758637        6 weeks ago         64.19 MB

artifactory.global.com/alpine        latest              965ea09ff2eb        8 weeks ago         5.548 MB

artifactory.global.com/hello-world   latest              fce289e99eb9        11 months ago       1.84 kB

 

Below command is used to run a Docker image as daemon (-d)

-d - stands for detached. Alternatively you can attach using -it (interactive)

-name - Unique name can be anything

-p - port mapping. 80 is server and 8080 is docker

Nigelpulton - It is the docker image name. Any image with / is not official

root@academy-rhel7[axessuser] # #docker run -d --name web -p 80:8080 nigelpulton/pluralsight-docker-ci

 

 

Below command  is used to get inside the docker container. Whereas when using it will run the container and control will come back to us

root@academy-rhel7[axessuser] # docker run -it --name temp ubuntu:latest /bin/bash

root@09bd84032112:/# root@academy-rhel7[axessuser] #

 

To exit from the container use control + p + q or else the container will get closed.

root@academy-rhel7[axessuser] # #CONTROL + p + q to exit without closing the process

 

root@academy-rhel7[axessuser] # docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

09bd84032112        ubuntu:latest       "/bin/bash"         4 minutes ago       Up 4 minutes                            temp

 

To  stop all container

root@academy-rhel7[axessuser] # docker stop $(docker ps -aq)

09bd84032112

0c8a7e686341

 

To remove all container

root@academy-rhel7[axessuser] # docker rm $(docker ps -aq)

09bd84032112

0c8a7e686341

 

root@academy-rhel7[axessuser] # docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

 

root@academy-rhel7[axessuser] # docker images

REPOSITORY                                             TAG                 IMAGE ID            CREATED             SIZE

artifactory.global.com/ubuntu        latest              775349758637        6 weeks ago         64.19 MB

artifactory.global.com/alpine        latest              965ea09ff2eb        8 weeks ago         5.548 MB

artifactory.global.com/hello-world   latest              fce289e99eb9        11 months ago       1.84 kB

 

To remove all images

root@academy-rhel7[axessuser] # docker rmi $(docker images -q)

Untagged: artifactory.global.com/ubuntu:latest

Untagged: artifactory.global.com/ubuntu@sha256:7c2e0528340e055e5b6d959d70a71a0a6932bd4de56385718d8e15c2295cd5a2

Deleted: sha256:775349758637aff77bf85e2ff0597e86e3e859183ef0baba8b3e8fc8d3cba51c

Deleted: sha256:4fc26b0b0c6903db3b4fe96856034a1bd9411ed963a96c1bc8f03f18ee92ac2a

Deleted: sha256:b53837dafdd21f67e607ae642ce49d326b0c30b39734b6710c682a50a9f932bf

Deleted: sha256:565879c6effe6a013e0b2e492f182b40049f1c083fc582ef61e49a98dca23f7e

Deleted: sha256:cc967c529ced563b7746b663d98248bc571afdb3c012019d7f54d6c092793b8b

Untagged: artifactory.global.com/alpine:latest

Untagged: artifactory.global.com/alpine@sha256:c19173c5ada610a5989151111163d28a67368362762534d8a8121ce95cf2bd5a

Deleted: sha256:965ea09ff2ebd2b9eeec88cd822ce156f6674c7e99be082c7efac3c62f3ff652

Deleted: sha256:77cae8ab23bf486355d1b3191259705374f4a11d483b24964d2f729dd8c076a0

Untagged: artifactory.global.com/hello-world:latest

Untagged: artifactory.global.com/hello-world@sha256:4fe721ccc2e8dc7362278a29dc660d833570ec2682f4e4194f4ee23e415e1064

Deleted: sha256:fce289e99eb9bca977dae136fbe2a82b6b7d4c372474c9235adc1741675f587e

Deleted: sha256:af0b15c8625bb1938f1d7b17081031f649fd14e6b233688eea3c5483994a66a3

root@academy-rhel7[axessuser] # docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

 

rm vs rmi:

rm is to remove the container

rmi is to remove images

 

Container Lifecycle: Container is running images. We can start, stop until we delete using "docker rm". To delete image we need first delete container.

 


No comments:

Post a Comment

Golang - Email - Secure code warrior

 package mail import ( "net/smtp" "gobin/config" ) var ( emailConfig config.Email ) type Mail struct { Destinati...