Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the general use of Docker?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "what is the regular use of Docker". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

7. Advanced level

In this section, we take running an Gitlab instance as an example to further introduce the general use of Docker.

Root@ubuntu:~# docker pull redis 7.1. Get the Redis image and run... Root@ubuntu:~# docker run-name gitlab-cache-d redis a2c183f16cee0aa30eca8f27875d3770ac1291fc22b218d4b5e673ce604074c87.2. Get the MySQL image and run root@ubuntu:~# mkdir-p / opt/test/gitlab/db/ root@ubuntu:~# docker pull mysql... Root@ubuntu:~# docker run-- name gitlab-db-e MYSQL_ROOT_PASSWORD=123456-d-p 3307 MYSQL_ROOT_PASSWORD=123456 3306-v / opt/test/gitlab/db:/var/lib/mysql mysql:5.7 7c8110b8151e2ddbc67d2bb1d96a9cc24ef68546a885d065e78bd274775ec7f7 create database directory map 7.3. Create the corresponding database and permissions root@ubuntu:~# docker exec-it gitlab-db / bin/bashroot@7c8110b8151e:/# mysql-uroot-p123456mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 4Server version: 5.7.9 MySQL Community Server (GPL) Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or'\ h' for help. Type'c'to clear the current input statement.mysql > CREATE USER 'gitlab'@'%.%' IDENTIFIED BY' password';Query OK, 0 rows affected (0.00 sec) mysql > CREATE DATABASE IF NOT EXISTS `gitlabhq_ production`DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ ci`; Query OK, 1 row affected (0.00 sec) mysql > GRANT ALL PRIVILEGES ON `gitlabhq_ production. * TO 'gitlab'@'%.%';Query OK, 0 rows affected (0.00 sec) mysql > exitByeroot@7c8110b8151e:/# exitexit

Exec means to enter a running container

The statements executed in MySQL can be found in: https://hub.docker.com/r/sameersbn/gitlab/#external-mysql-server7.4. Get the Gitlab image root@ubuntu:~# mkdir-p / opt/test/gitlab/data root@ubuntu:~# docker pull sameersbn/gitlab to create the GIT data directory map 7.5. Run the Gitlab image root@ubuntu:~# docker run-- name=gitlab-d\-e GITLAB_PORT=10080\-e GITLAB_SSH_PORT=10022\-e GITLAB_HOST=inner.ecfront.com\-e DB_TYPE=mysql\-e DB_HOST=192.168.4.99\-e DB_PORT=3307\-e DB_NAME=gitlabhq_production\-e DB_USER=gitlab\-e DB_PASS=password\-e GITLAB_EMAIL=git@ecfront.com\-e SMTP_ENABLED=true\-e SMTP_DOMAIN=ecfront Com\-e SMTP_HOST=smtp.exmail.qq.com\-e SMTP_PORT=25\-e SMTP_USER=git@ecfront.com\-e SMTP_PASS=xxx\-e SMTP_AUTHENTICATION=login\-e NGINX_MAX_UPLOAD_SIZE=512m\-e GITLAB_BACKUPS=monthly\-p 10022 SMTP_AUTHENTICATION=login 22\-p 10080 sameersbn/gitlab 80\-v / opt/test/gitlab/data:/home/git/data\-link gitlab-cache:redisio\-- dns=192.168.4.99\ sameersbn/gitlab

HTTP service port

SSH request port

Service domain name

Database connection information

Email information

To solve the problem of `RPC failed; result=22, HTTP code = 413`, see http://stackoverflow.com/questions/7489813/github-push-error-rpc-failed-result-22-http-code-413

Backup strategy, daily

SSH request port mapping

HTTP request port mapping

GIT data directory mapping

Connect the Reids container to implement caching

Configure DNS

If you use the MySQL database, you must add-e DB_TYPE=mysql, otherwise the container will connect to the default Postgre type and will not be able to start.

-- dns is used to specify the DNS of the container. We can specify a common DNS to implement the mutual PING of different containers.

By default, Docker cannot access each other between containers. There are two main ways to achieve interaction. One is to use-- link, which is also recommended by Docker, to establish a Host record of the Link container in the container to achieve one-way access, and the other is to implement open service calls. For the above cases, Redis uses Link and MySQL uses open service.

Visit: http://192.168.4.99:10080 (192.168.4.99 is the IP of my host), etc., why can't you access it?

7.6. View the running log

When something goes wrong, the first thing we think about is to look at the log. The log of the Docker container is as follows:

Root@ubuntu:~# docker logs gitlab ERROR: Please configure the GITLAB_SECRETS_DB_KEY_BASE parameter. Cannot continue. Aborting...

If the GITLAB_SECRETS_DB_KEY_BASE variable is required, check the official description:

Note: Since GitLab 8.0.0 you need to provide the GITLAB_SECRETS_DB_KEY_BASE parameter while starting the image.

Tip: You can generate a random string using pwgen-Bsv1 64 and assign it as the value ofGITLAB_SECRETS_DB_KEY_BASE.

-https://hub.docker.com/r/sameersbn/gitlab/

Okay, let's use pwgen-Bsv1 64 to generate a key

Root@ubuntu:~# pwgen-Bsv1 64 7hpTqCXgf4tVbnFmdC7PNn9n4hWmCnvF479fsJtcdTkhmVfWfzpwTJ4sNRzNkkXf

Add GITLAB_SECRETS_DB_KEY_BASE to rerun

Root@ubuntu:~# docker rm-f gitlabroot@ubuntu:~# docker run-- name=gitlab-d\-e GITLAB_PORT=10080\-e GITLAB_SSH_PORT=10022\-e GITLAB_HOST=inner.ecfront.com\-e DB_TYPE=mysql\-e DB_HOST=192.168.4.99\-e DB_PORT=3307\-e DB_NAME=gitlabhq_production\-e DB_USER=gitlab\-e DB_PASS=password\-e GITLAB_SECRETS_DB_KEY_BASE=7hpTqCXgf4tVbnFmdC7PNn9n4hWmCnvF479fsJtcdTkhmVfWfzpwTJ4sNRzNkkXf\-e GITLAB_EMAIL=git @ ecfront.com\-e SMTP_ENABLED=true\-e SMTP_DOMAIN=ecfront.com\-e SMTP_PORT=25\-e SMTP_USER=git@ecfront.com\-e SMTP_PASS=xxx\-e SMTP_AUTHENTICATION=login\-e NGINX_MAX_UPLOAD_SIZE=512m\-e GITLAB_BACKUPS=monthly\-p 10022 SMTP_DOMAIN=ecfront.com 22\-p 10080 opt/test/gitlab/data:/home/git/data 80\-v / opt/test/gitlab/data:/home/git/data\-- Link gitlab-cache:redisio\-dns=192.168.4.99\ sameersbn/gitlab7.7. Complete

All right, there are a lot of things to do for the first time, so we can open the page after a while.

User name: root password: 5iveLSecretfe "what is the regular use of Docker" content is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report