docker_basic_configuration

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docker_basic_configuration [2020/01/23 12:26] andonovjdocker_basic_configuration [2020/01/25 04:02] (current) – external edit 127.0.0.1
Line 1: Line 1:
-======Overview======+=====Overview======
 Docker configuration is done in the YML files, where we should describe what we want and how that should be linked in regards to: Docker configuration is done in the YML files, where we should describe what we want and how that should be linked in regards to:
  
Line 5: Line 5:
   * Network   * Network
   * Ports   * Ports
 +
 +
 +=====Installation=====
 +Docker is open source application and can be freely downloaded and installed.
 +Now it is important to notice that, in general docker installed on Windows will run windows apps and docker installed on Linux will run Linux apps.
 +Of course, there are exception of that rule and Linux docker can run Windows apps, but that is story for another time.
 +Docker is easily installed as follows:
 +
 +====Install the package====
 +You can install the package using your favorite package manager, in my case "yum"
 +<sxh bash>
 +[root@postgresqlmaster yum.repos.d]# cat docker.repo
 +[dockerrepo]
 +name=Docker Repository
 +baseurl=https://yum.dockerproject.org/repo/main/centos/7/
 +enabled=1
 +gpgcheck=1
 +gpgkey=https://yum.dockerproject.org/gpg
 +[root@postgresqlmaster yum.repos.d]#
 +[root@postgresqlpgpool app]# yum install docker-ce docker-ce-cli containerd.io
 +Loaded plugins: fastestmirror, langpacks
 +Loading mirror speeds from cached hostfile
 + * base: ftp.cvut.cz
 + * extras: ftp.cvut.cz
 + * updates: ftp.cvut.cz
 +Resolving Dependencies
 +--> Running transaction check
 +---> Package containerd.io.x86_64 0:1.2.10-3.2.el7 will be installed
 +---> Package docker-ce.x86_64 3:19.03.5-3.el7 will be installed
 +---> Package docker-ce-cli.x86_64 1:19.03.5-3.el7 will be installed
 +--> Finished Dependency Resolution
 +
 +Dependencies Resolved
 +
 +===========================================================================================================================================================================================================================
 + Package                                              Arch                                          Version                                                  Repository                                               Size
 +===========================================================================================================================================================================================================================
 +Installing:
 + containerd.io                                        x86_64                                        1.2.10-3.2.el7                                           docker-ce-stable                                         23 M
 + docker-ce                                            x86_64                                        3:19.03.5-3.el7                                          docker-ce-stable                                         24 M
 + docker-ce-cli                                        x86_64                                        1:19.03.5-3.el7                                          docker-ce-stable                                         39 M
 +
 +Transaction Summary
 +===========================================================================================================================================================================================================================
 +Install  3 Packages
 +
 +Total size: 87 M
 +Installed size: 362 M
 +Is this ok [y/d/N]: y
 +Downloading packages:
 +Running transaction check
 +Running transaction test
 +Transaction test succeeded
 +Running transaction
 +  Installing : 1:docker-ce-cli-19.03.5-3.el7.x86_64                                                                                                                                                                    1/3
 +  Installing : containerd.io-1.2.10-3.2.el7.x86_64                                                                                                                                                                     2/3
 +  Installing : 3:docker-ce-19.03.5-3.el7.x86_64                                                                                                                                                                        3/3
 +  Verifying  : containerd.io-1.2.10-3.2.el7.x86_64                                                                                                                                                                     1/3
 +  Verifying  : 1:docker-ce-cli-19.03.5-3.el7.x86_64                                                                                                                                                                    2/3
 +  Verifying  : 3:docker-ce-19.03.5-3.el7.x86_64                                                                                                                                                                        3/3
 +
 +Installed:
 +  containerd.io.x86_64 0:1.2.10-3.2.el7                                     docker-ce.x86_64 3:19.03.5-3.el7                                     docker-ce-cli.x86_64 1:19.03.5-3.el7
 +
 +Complete!
 +[root@postgresqlpgpool app]# service docker start
 +Redirecting to /bin/systemctl start docker.service
 +[root@postgresqlpgpool app]
 +</sxh>
 +
 +====Start the service====
 +<sxh bash>
 +[root@postgresqlmaster yum.repos.d]# service docker start
 +Redirecting to /bin/systemctl start docker.service
 +[root@postgresqlmaster yum.repos.d]# service docker status
 +Redirecting to /bin/systemctl status docker.service
 +● docker.service - Docker Application Container Engine
 +   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
 +   Active: active (running) since Thu 2020-01-23 07:36:43 EST; 1min 56s ago
 +     Docs: https://docs.docker.com
 + Main PID: 3890 (dockerd)
 +    Tasks: 19
 +   Memory: 34.0M
 +   CGroup: /system.slice/docker.service
 +           ├─3890 /usr/bin/dockerd
 +           └─3893 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd...
 +
 +Jan 23 07:36:42 postgresqlmaster systemd[1]: Starting Docker Application Container Engine...
 +Jan 23 07:36:42 postgresqlmaster dockerd[3890]: time="2020-01-23T07:36:42.412010221-05:00" level=info msg="libcontainerd: new containerd process, pid: 3893"
 +Jan 23 07:36:43 postgresqlmaster dockerd[3890]: time="2020-01-23T07:36:43.573133278-05:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
 +Jan 23 07:36:43 postgresqlmaster dockerd[3890]: time="2020-01-23T07:36:43.573865294-05:00" level=info msg="Loading containers: start."
 +Jan 23 07:36:43 postgresqlmaster dockerd[3890]: time="2020-01-23T07:36:43.768519625-05:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can...red IP address"
 +Jan 23 07:36:43 postgresqlmaster dockerd[3890]: time="2020-01-23T07:36:43.867416058-05:00" level=info msg="Loading containers: done."
 +Jan 23 07:36:43 postgresqlmaster dockerd[3890]: time="2020-01-23T07:36:43.879638594-05:00" level=info msg="Daemon has completed initialization"
 +Jan 23 07:36:43 postgresqlmaster dockerd[3890]: time="2020-01-23T07:36:43.879659977-05:00" level=info msg="Docker daemon" commit=89658be graphdriver=overlay version=17.05.0-ce
 +Jan 23 07:36:43 postgresqlmaster dockerd[3890]: time="2020-01-23T07:36:43.889952934-05:00" level=info msg="API listen on /var/run/docker.sock"
 +Jan 23 07:36:43 postgresqlmaster systemd[1]: Started Docker Application Container Engine.
 +Hint: Some lines were ellipsized, use -l to show in full.
 +</sxh>
 +
 +====Run "Hello World"====
 +<sxh bash>
 +[root@postgresqlmaster yum.repos.d]# docker run hello-world
 +Unable to find image 'hello-world:latest' locally
 +latest: Pulling from library/hello-world
 +1b930d010525: Pull complete
 +Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f
 +Status: Downloaded newer image for hello-world:latest
 +
 +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/                 <-- Here you can find A LOT OF dockerized applications (images)
 +
 +For more examples and ideas, visit:
 + https://docs.docker.com/get-started/
 +
 +[root@postgresqlmaster yum.repos.d]#
 +
 +
 +</sxh>
 +=====Configurations=====
 +With docker we can download and run any image from a registry. Currently there are over 3 million dockerized applications including:
 +
 +  * Databases
 +  * Web Services
 +  * Operation Systems and others
 +
 +You can download and run such images from any registry, but the most popular is: [[https://hub.docker.com || this one]].
  
 Let's start by downloading and installing MySQL database which has been dockerized. Let's start by downloading and installing MySQL database which has been dockerized.
  
-===MySQL Configuration===+====MySQL Docker====
 Once we have docker installed, we can search and install any image we want: Once we have docker installed, we can search and install any image we want:
  
Line 58: Line 200:
 </sxh> </sxh>
  
-By default the "hello-world" image is always installed and can be run as follows: +===Install MySQL=== 
- +Now we can install the mysql image using the following commands:
-<sxh bash> +
-[root@localhost ~]# docker run hello-world +
-Unable to find image 'hello-world:latest' locally +
-latest: Pulling from library/hello-world +
-9db2ca6ccae0: Pull complete +
-Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc +
-Status: Downloaded newer image for hello-world:latest +
- +
-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/engine/userguide/ +
-</sxh> +
- +
- +
-Now we can install the mysql image as follows:+
  
 <sxh bash> <sxh bash>
Line 121: Line 231:
 cloudfoundry/cf-mysql-ci                               Image used in CI of cf-mysql-release            0 cloudfoundry/cf-mysql-ci                               Image used in CI of cf-mysql-release            0
 ansibleplaybookbundle/mysql-apb                        An APB which deploys RHSCL MySQL                0                                       [OK] ansibleplaybookbundle/mysql-apb                        An APB which deploys RHSCL MySQL                0                                       [OK]
 +
 +</sxh>
 +
 +===Download (pull) MySQL)===
 +<sxh bash>
 [root@localhost ~]# docker pull mysql [root@localhost ~]# docker pull mysql
 Using default tag: latest Using default tag: latest
Line 133: Line 248:
 [root@localhost ~]# docker images [root@localhost ~]# docker images
 REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
-mysql                latest              5dbe5b6313e1        13 hours ago        445MB 
 hello-world          latest              2cb0d9787c4d        2 weeks ago         1.85kB hello-world          latest              2cb0d9787c4d        2 weeks ago         1.85kB
-mysql/mysql-server   latest              02d081b9c73e        3 months ago        300MB+mysql   latest              02d081b9c73e        3 months ago        300MB
 </sxh> </sxh>
  
- +===Start the MySQL=== 
-We can see now, that I have installed 2 mysqls, we can initiate a new container for mysql image as follows: +We can see now, that I have installed mysql, we can initiate a new container for mysql image as follows:
  
 <sxh bash> <sxh bash>
-[root@localhost ~]# docker run --name mysql2 -e MYSQL_ROOT_PASSWORD='oracle' -d mysql/mysql-server:latest +[root@postgresqlmaster yum.repos.d]#  docker run --name mysql -e MYSQL_ROOT_PASSWORD='oracle' -d mysql 
-0cb5ef2781b253a98f67028ca7f9b2e6934ee8560718401f54bd46e07a9972d6+d434caf757cfc946d074fbabe44c9a14117d18b8e0451d06afb81a94facbe540
 [root@localhost ~]# [root@localhost ~]#
 </sxh> </sxh>
  
 +===Login to the host===
 +<sxh bash>
 +[root@postgresqlmaster yum.repos.d]# docker container ls
 +CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                 NAMES
 +d434caf757cf        mysql               "docker-entrypoint..."   7 seconds ago       Up 6 seconds        3306/tcp, 33060/tcp   mysql
 +[root@postgresqlmaster yum.repos.d]# docker exec -it d434caf757cf /bin/bash
 +root@d434caf757cf:/#
 +
 +</sxh>
 +
 +
 +===Connect to the DB===
 +And voila we can connect to the DB :)
 +<sxh bash>
 +[root@localhost ~]# docker exec -it d434caf757c mysql -uroot -p   <- 'oracle'
 +Enter password:
 +Welcome to the MySQL monitor.  Commands end with ; or \g.
 +Your MySQL connection id is 14
 +Server version: 8.0.11 MySQL Community Server - GPL
 +
 +Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
 +
 +Oracle is a registered trademark of Oracle Corporation and/or its
 +affiliates. Other names may be trademarks of their respective
 +owners.
 +
 +Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 +mysql>
 +</sxh>
  
 +===Check Logs===
 We can check the logs of the installation as follows: We can check the logs of the installation as follows:
  
Line 225: Line 368:
 Finally, we can connect to the mysql, by running the mysql command from the docker: Finally, we can connect to the mysql, by running the mysql command from the docker:
  
-<sxh bash> +====Mongo Configuration==== 
-[root@localhost ~]# docker exec -it mysql2 mysql -uroot -p   <- 'oracle' +Other configuration which can use is for Mongo database:
-Enter password: +
-Welcome to the MySQL monitor.  Commands end with ; or \g. +
-Your MySQL connection id is 14 +
-Server version: 8.0.11 MySQL Community Server - GPL +
- +
-Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. +
- +
-Oracle is a registered trademark of Oracle Corporation and/or its +
-affiliates. Other names may be trademarks of their respective +
-owners. +
- +
-Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. +
-mysql> +
-</sxh> +
- +
- +
- +
-Here is example of such configuration of Mongo database container: +
  
 <sxh bash> <sxh bash>
  • docker_basic_configuration.1579782363.txt.gz
  • Last modified: 2020/01/23 20:26
  • (external edit)