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 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:
You can install the package using your favorite package manager, in my case “yum”
[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]
[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.
[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]#
With docker we can download and run any image from a registry. Currently there are over 3 million dockerized applications including:
You can download and run such images from any registry, but the most popular is: | this one.
Let's start by downloading and installing MySQL database which has been dockerized.
Once we have docker installed, we can search and install any image we want:
[root@localhost ~]# docker info Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 18.06.0-ce Storage Driver: overlay2 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: d64c661f1d51c48782c9cec8fda7604785f93587 runc version: 69663f0bd4b60df09991c08812a60108003fa340 init version: fec3683 Security Options: seccomp Profile: default Kernel Version: 3.10.0-693.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 1.796GiB Name: localhost.localdomain ID: JJ7T:TB2D:ODDZ:7TEB:P5QQ:TVYO:VGRK:76SO:2XXP:7Q47:2P77:KHEG Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false
Now we can install the mysql image using the following commands:
[root@localhost ~]# docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relation… 6616 [OK] mariadb MariaDB is a community-developed fork of MyS… 2101 [OK] mysql/mysql-server Optimized MySQL Server Docker images. Create… 485 [OK] percona Percona Server is a fork of the MySQL relati… 350 [OK] zabbix/zabbix-server-mysql Zabbix Server with MySQL database support 108 [OK] hypriot/rpi-mysql RPi-compatible Docker Image with Mysql 90 zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server wi… 61 [OK] centurylink/mysql Image containing mysql. Optimized to be link… 60 [OK] 1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 38 [OK] tutum/mysql Base docker image to run a MySQL database se… 32 centos/mysql-57-centos7 MySQL 5.7 SQL database server 31 mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 31 schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backup… 20 [OK] bitnami/mysql Bitnami MySQL Docker Image 16 [OK] zabbix/zabbix-proxy-mysql Zabbix proxy with MySQL database support 15 [OK] linuxserver/mysql A Mysql container, brought to you by LinuxSe… 14 centos/mysql-56-centos7 MySQL 5.6 SQL database server 8 circleci/mysql MySQL is a widely used, open-source relation… 6 openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6 dsteinkopf/backup-all-mysql backup all DBs in a mysql server 4 [OK] mysql/mysql-router MySQL Router provides transparent routing be… 2 openzipkin/zipkin-mysql Mirror of https://quay.io/repository/openzip… 1 cloudposse/mysql Improved `mysql` service with support for `m… 0 [OK] cloudfoundry/cf-mysql-ci Image used in CI of cf-mysql-release 0 ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 0 [OK]
[root@localhost ~]# docker pull mysql Using default tag: latest latest: Pulling from library/mysql be8881be8156: Pull complete c3995dabd1d7: Pull complete
We can check installed images of course and see how much space they occupy:
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 2cb0d9787c4d 2 weeks ago 1.85kB mysql latest 02d081b9c73e 3 months ago 300MB
We can see now, that I have installed mysql, we can initiate a new container for mysql image as follows:
[root@postgresqlmaster yum.repos.d]# docker run --name mysql -e MYSQL_ROOT_PASSWORD='oracle' -d mysql d434caf757cfc946d074fbabe44c9a14117d18b8e0451d06afb81a94facbe540 [root@localhost ~]#
[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:/#
And voila we can connect to the DB :)
[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>
We can check the logs of the installation as follows:
[root@localhost ~]# docker logs -f mysql2 [Entrypoint] MySQL Docker Image 8.0.11-1.1.5 [Entrypoint] Initializing database 2018-07-27T15:28:10.177501Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.11) initializing of server in progress as process 21 mbind: Operation not permitted 2018-07-27T15:28:15.362667Z 5 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. 2018-07-27T15:28:17.111421Z 5 [Warning] [MY-010315] [Server] 'user' entry 'mysql.infoschema@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:17.111452Z 5 [Warning] [MY-010315] [Server] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:17.111460Z 5 [Warning] [MY-010315] [Server] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:17.111467Z 5 [Warning] [MY-010315] [Server] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:17.111479Z 5 [Warning] [MY-010323] [Server] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:17.111484Z 5 [Warning] [MY-010323] [Server] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:17.111492Z 5 [Warning] [MY-010311] [Server] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:17.111603Z 5 [Warning] [MY-010330] [Server] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:17.111612Z 5 [Warning] [MY-010330] [Server] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:18.279696Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.11) initializing of server has completed [Entrypoint] Database initialized 2018-07-27T15:28:21.900080Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.11) starting as process 67 mbind: Operation not permitted 2018-07-27T15:28:22.282453Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2018-07-27T15:28:22.290888Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.infoschema@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:22.290910Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:22.290919Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:22.290926Z 0 [Warning] [MY-010315] [Server] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:22.290942Z 0 [Warning] [MY-010323] [Server] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:22.290947Z 0 [Warning] [MY-010323] [Server] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:22.290956Z 0 [Warning] [MY-010311] [Server] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:22.292825Z 0 [Warning] [MY-010330] [Server] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:22.292838Z 0 [Warning] [MY-010330] [Server] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:22.296561Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.11' socket: '/var/lib/mysql/mysql.sock' port: 0 MySQL Community Server - GPL. Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it. 2018-07-27T15:28:24.404253Z 9 [Warning] [MY-010315] [Server] 'user' entry 'healthchecker@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:24.404283Z 9 [Warning] [MY-010315] [Server] 'user' entry 'mysql.infoschema@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:24.404293Z 9 [Warning] [MY-010315] [Server] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:24.404300Z 9 [Warning] [MY-010315] [Server] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:24.404307Z 9 [Warning] [MY-010315] [Server] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:24.404320Z 9 [Warning] [MY-010323] [Server] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:24.404325Z 9 [Warning] [MY-010323] [Server] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:24.404333Z 9 [Warning] [MY-010311] [Server] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:24.404409Z 9 [Warning] [MY-010330] [Server] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:24.404417Z 9 [Warning] [MY-010330] [Server] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode. [Entrypoint] ignoring /docker-entrypoint-initdb.d/* mbind: Operation not permitted 2018-07-27T15:28:27.123116Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.11) MySQL Community Server - GPL. [Entrypoint] Server shut down [Entrypoint] MySQL init process done. Ready for start up. [Entrypoint] Starting MySQL 8.0.11-1.1.5 2018-07-27T15:28:27.607070Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.11) starting as process 1 mbind: Operation not permitted 2018-07-27T15:28:28.013191Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2018-07-27T15:28:28.024200Z 0 [Warning] [MY-010315] [Server] 'user' entry 'healthchecker@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:28.024228Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.infoschema@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:28.024237Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:28.024245Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:28.024251Z 0 [Warning] [MY-010315] [Server] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:28.024266Z 0 [Warning] [MY-010323] [Server] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:28.024271Z 0 [Warning] [MY-010323] [Server] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:28.024280Z 0 [Warning] [MY-010311] [Server] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:28.026295Z 0 [Warning] [MY-010330] [Server] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:28.026307Z 0 [Warning] [MY-010330] [Server] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode. 2018-07-27T15:28:28.029599Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.11' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.
Finally, we can connect to the mysql, by running the mysql command from the docker:
Other configuration which can use is for Mongo database:
incidenttool_mongo: image: mongo volumes: - incidenttool_mongodb:/data/db - incidenttool_mongodb_config:/data/configdb - /apphome/backup/bulk_copied:/data/db/dump ports: - 27017:27017 networks: - incidenttool environment: - "TZ=UTC" - "MONGO_INITDB_ROOT_USERNAME=root" - "MONGO_INITDB_ROOT_PASSWORD=password" volumes: incidenttool_mongodb: incidenttool_mongodb_config: networks: incidenttool: driver: bridge ipam: config: - subnet: 172.31.254.0/28
In case of changes, you have to restart the container is follows:
docker-compose -p production up -d incidenttool_mongo