This is an old revision of the document!
Overvie
Docker configuration is done in the YML files, where we should describe what we want and how that should be linked in regards to:
- Storage
- Network
- 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:
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: | this one.
Let's start by downloading and installing MySQL database which has been dockerized.
MySQL Configuration
Once we have docker installed, we can search and install any image we want:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
[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 |
By default the “hello-world” image is always installed and can be run as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
[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/ |
Now we can install the mysql image as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
[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:
1 2 3 4 5 |
[root@localhost ~] # docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql latest 5dbe5b6313e1 13 hours ago 445MB hello-world latest 2cb0d9787c4d 2 weeks ago 1.85kB mysql /mysql-server latest 02d081b9c73e 3 months ago 300MB |
We can see now, that I have installed 2 mysqls, we can initiate a new container for mysql image as follows:
1 2 3 |
[root@localhost ~] # docker run --name mysql2 -e MYSQL_ROOT_PASSWORD='oracle' -d mysql/mysql-server:latest 0cb5ef2781b253a98f67028ca7f9b2e6934ee8560718401f54bd46e07a9972d6 [root@localhost ~] # |
We can check the logs of the installation as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
[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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@localhost ~] # docker exec -it mysql2 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> |
Mongo Configuration
Other configuration which can use is for Mongo database:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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:
1 |
docker-compose -p production up -d incidenttool_mongo |