Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
docker_basic_configuration [2020/01/20 12:48] – andonovj | docker_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 6: | Line 6: | ||
* Ports | * Ports | ||
- | Here is example of such configuration of Mongo database container: | ||
+ | =====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 " | ||
+ | <sxh bash> | ||
+ | [root@postgresqlmaster yum.repos.d]# | ||
+ | [dockerrepo] | ||
+ | name=Docker Repository | ||
+ | baseurl=https:// | ||
+ | enabled=1 | ||
+ | gpgcheck=1 | ||
+ | gpgkey=https:// | ||
+ | [root@postgresqlmaster yum.repos.d]# | ||
+ | [root@postgresqlpgpool app]# yum install docker-ce docker-ce-cli containerd.io | ||
+ | Loaded plugins: fastestmirror, | ||
+ | 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: | ||
+ | ---> Package docker-ce.x86_64 3: | ||
+ | ---> Package docker-ce-cli.x86_64 1: | ||
+ | --> Finished Dependency Resolution | ||
+ | |||
+ | Dependencies Resolved | ||
+ | |||
+ | =========================================================================================================================================================================================================================== | ||
+ | | ||
+ | =========================================================================================================================================================================================================================== | ||
+ | Installing: | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | Transaction Summary | ||
+ | =========================================================================================================================================================================================================================== | ||
+ | Install | ||
+ | |||
+ | 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: | ||
+ | Installing : containerd.io-1.2.10-3.2.el7.x86_64 | ||
+ | Installing : 3: | ||
+ | Verifying | ||
+ | Verifying | ||
+ | Verifying | ||
+ | |||
+ | Installed: | ||
+ | containerd.io.x86_64 0: | ||
+ | |||
+ | Complete! | ||
+ | [root@postgresqlpgpool app]# service docker start | ||
+ | Redirecting to / | ||
+ | [root@postgresqlpgpool app] | ||
+ | </ | ||
+ | |||
+ | ====Start the service==== | ||
+ | <sxh bash> | ||
+ | [root@postgresqlmaster yum.repos.d]# | ||
+ | Redirecting to / | ||
+ | [root@postgresqlmaster yum.repos.d]# | ||
+ | Redirecting to / | ||
+ | ● docker.service - Docker Application Container Engine | ||
+ | | ||
+ | | ||
+ | Docs: https:// | ||
+ | Main PID: 3890 (dockerd) | ||
+ | Tasks: 19 | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | Jan 23 07:36:42 postgresqlmaster systemd[1]: Starting Docker Application Container Engine... | ||
+ | Jan 23 07:36:42 postgresqlmaster dockerd[3890]: | ||
+ | Jan 23 07:36:43 postgresqlmaster dockerd[3890]: | ||
+ | Jan 23 07:36:43 postgresqlmaster dockerd[3890]: | ||
+ | Jan 23 07:36:43 postgresqlmaster dockerd[3890]: | ||
+ | Jan 23 07:36:43 postgresqlmaster dockerd[3890]: | ||
+ | Jan 23 07:36:43 postgresqlmaster dockerd[3890]: | ||
+ | Jan 23 07:36:43 postgresqlmaster dockerd[3890]: | ||
+ | Jan 23 07:36:43 postgresqlmaster dockerd[3890]: | ||
+ | Jan 23 07:36:43 postgresqlmaster systemd[1]: Started Docker Application Container Engine. | ||
+ | Hint: Some lines were ellipsized, use -l to show in full. | ||
+ | </ | ||
+ | |||
+ | ====Run "Hello World" | ||
+ | <sxh bash> | ||
+ | [root@postgresqlmaster yum.repos.d]# | ||
+ | Unable to find image ' | ||
+ | latest: Pulling from library/ | ||
+ | 1b930d010525: | ||
+ | Digest: sha256: | ||
+ | Status: Downloaded newer image for hello-world: | ||
+ | |||
+ | 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 " | ||
+ | (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: | ||
+ | | ||
+ | |||
+ | For more examples and ideas, visit: | ||
+ | | ||
+ | |||
+ | [root@postgresqlmaster yum.repos.d]# | ||
+ | |||
+ | |||
+ | </ | ||
+ | =====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:// | ||
+ | |||
+ | Let's start by downloading and installing MySQL database which has been dockerized. | ||
+ | |||
+ | ====MySQL Docker==== | ||
+ | Once we have docker installed, we can search and install any image we want: | ||
+ | |||
+ | <sxh bash> | ||
+ | [root@localhost ~]# docker info | ||
+ | Containers: 0 | ||
+ | | ||
+ | | ||
+ | | ||
+ | Images: 0 | ||
+ | Server Version: 18.06.0-ce | ||
+ | Storage Driver: overlay2 | ||
+ | | ||
+ | | ||
+ | | ||
+ | Logging Driver: json-file | ||
+ | Cgroup Driver: cgroupfs | ||
+ | Plugins: | ||
+ | | ||
+ | | ||
+ | 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: | ||
+ | | ||
+ | Profile: default | ||
+ | Kernel Version: 3.10.0-693.el7.x86_64 | ||
+ | Operating System: CentOS Linux 7 (Core) | ||
+ | OSType: linux | ||
+ | Architecture: | ||
+ | CPUs: 1 | ||
+ | Total Memory: 1.796GiB | ||
+ | Name: localhost.localdomain | ||
+ | ID: JJ7T: | ||
+ | Docker Root Dir: / | ||
+ | Debug Mode (client): false | ||
+ | Debug Mode (server): false | ||
+ | Registry: https:// | ||
+ | Labels: | ||
+ | Experimental: | ||
+ | Insecure Registries: | ||
+ | | ||
+ | Live Restore Enabled: false | ||
+ | </ | ||
+ | |||
+ | ===Install MySQL=== | ||
+ | Now we can install the mysql image using the following commands: | ||
+ | |||
+ | <sxh bash> | ||
+ | [root@localhost ~]# docker search mysql | ||
+ | NAME | ||
+ | mysql MySQL is a widely used, open-source relation… | ||
+ | mariadb | ||
+ | mysql/ | ||
+ | percona | ||
+ | zabbix/ | ||
+ | hypriot/ | ||
+ | zabbix/ | ||
+ | centurylink/ | ||
+ | 1and1internet/ | ||
+ | tutum/ | ||
+ | centos/ | ||
+ | mysql/ | ||
+ | schickling/ | ||
+ | bitnami/ | ||
+ | zabbix/ | ||
+ | linuxserver/ | ||
+ | centos/ | ||
+ | circleci/ | ||
+ | openshift/ | ||
+ | dsteinkopf/ | ||
+ | mysql/ | ||
+ | openzipkin/ | ||
+ | cloudposse/ | ||
+ | cloudfoundry/ | ||
+ | ansibleplaybookbundle/ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===Download (pull) MySQL)=== | ||
+ | <sxh bash> | ||
+ | [root@localhost ~]# docker pull mysql | ||
+ | Using default tag: latest | ||
+ | latest: Pulling from library/ | ||
+ | be8881be8156: | ||
+ | c3995dabd1d7: | ||
+ | </ | ||
+ | |||
+ | We can check installed images of course and see how much space they occupy: | ||
+ | |||
+ | <sxh bash> | ||
+ | [root@localhost ~]# docker images | ||
+ | REPOSITORY | ||
+ | hello-world | ||
+ | mysql | ||
+ | </ | ||
+ | |||
+ | ===Start the MySQL=== | ||
+ | We can see now, that I have installed mysql, we can initiate a new container for mysql image as follows: | ||
+ | |||
+ | <sxh bash> | ||
+ | [root@postgresqlmaster yum.repos.d]# | ||
+ | d434caf757cfc946d074fbabe44c9a14117d18b8e0451d06afb81a94facbe540 | ||
+ | [root@localhost ~]# | ||
+ | </ | ||
+ | |||
+ | ===Login to the host=== | ||
+ | <sxh bash> | ||
+ | [root@postgresqlmaster yum.repos.d]# | ||
+ | CONTAINER ID IMAGE | ||
+ | d434caf757cf | ||
+ | [root@postgresqlmaster yum.repos.d]# | ||
+ | root@d434caf757cf:/# | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | ===Connect to the DB=== | ||
+ | And voila we can connect to the DB :) | ||
+ | <sxh bash> | ||
+ | [root@localhost ~]# docker exec -it d434caf757c mysql -uroot -p <- ' | ||
+ | Enter password: | ||
+ | Welcome to the MySQL monitor. | ||
+ | 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 ' | ||
+ | mysql> | ||
+ | </ | ||
+ | |||
+ | ===Check Logs=== | ||
+ | We can check the logs of the installation as follows: | ||
+ | |||
+ | <sxh bash> | ||
+ | [root@localhost ~]# docker logs -f mysql2 | ||
+ | [Entrypoint] MySQL Docker Image 8.0.11-1.1.5 | ||
+ | [Entrypoint] Initializing database | ||
+ | 2018-07-27T15: | ||
+ | mbind: Operation not permitted | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | [Entrypoint] Database initialized | ||
+ | 2018-07-27T15: | ||
+ | mbind: Operation not permitted | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | Warning: Unable to load '/ | ||
+ | Warning: Unable to load '/ | ||
+ | Warning: Unable to load '/ | ||
+ | Warning: Unable to load '/ | ||
+ | Warning: Unable to load '/ | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | |||
+ | [Entrypoint] ignoring / | ||
+ | |||
+ | mbind: Operation not permitted | ||
+ | 2018-07-27T15: | ||
+ | [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: | ||
+ | mbind: Operation not permitted | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | 2018-07-27T15: | ||
+ | </ | ||
+ | |||
+ | Finally, we can connect to the mysql, by running the mysql command from the docker: | ||
+ | |||
+ | ====Mongo Configuration==== | ||
+ | Other configuration which can use is for Mongo database: | ||
<sxh bash> | <sxh bash> |