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

Docker installation documentation

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

Share

Shulou(Shulou.com)06/03 Report--

1. Docker environment installation

System requirements: CentOS 7

To install docker through yum, first configure the yum mirror source and use the Ali cloud mirror.

Curl-o / etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

Then install and set up boot

Yum install docker-cesystemctl enable docker

Before starting the docker service, configure the docker storage directory (image / container) to store it in a larger partition. It is assumed to be / opt.

Mkdir / etc/dockertouch / etc/docker/daemon.json

Write the contents of / etc/docker/daemon.json.

{"data-root": "/ opt/docker", "registry-mirrors": ["https://registry.docker-cn.com"," https://docker.mirrors.ustc.edu.cn"]}

Docker-ce changes the graph field to data-root

The data-root field is all the images of docker. The location where the container is stored and the / opt/docker directory need not exist in advance. It will be created automatically when the docker service is started.

The registry-mirrors field is the acceleration list of domestic mirror sources (in the case of Fire Tree, it is useless because there is no network connection).

Finally, start the docker service.

Systemctl start docker1.1 copy shortcut command

Append the contents of the bash_docker.sh file to the end of the / root/.bashrc file, and then source / root/.bashrc to make it effective.

This file contains a commonly used command docker-enter.

Docker-enter container name / container id: enter the target container and you will get a bash command line

$docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc98790552123 reg01.sky-mobi.com/huoshu/nginx:1.0.0 "/ bin/sh-c 'servi..." 2 hours ago Up 2 hours 0.0. 0.0 80-81-> 80-81/tcp quizzical_shannon$ docker-enter c98790552123 [root@c98790552123 ~] # 1.2 Custom Network

By default, the docker container launched on each host is in a small local area network, similar to a virtual machine, and all traffic is forwarded by nat through the host, which is also the way routers work.

However, this approach is similar to dhcp, where the IP obtained by each startup of the container is uncertain. In order to ensure that the address of each project container is fixed, we need to create a custom docker LAN and specify the IP of the container when starting the container.

Note: the purpose of this operation is to keep the address of the project container fixed, for example, the redis and oracle address written in the project configuration file, the IP and port address of the back-end project monitor in the nginx configuration file, etc., which is not convenient to change frequently.

However, oracle is currently on a separate server, so there is no need to create this network. Just do the following on the server where the redis and the project container are located. As follows

$docker network create-subnet=172.21.0.0/16 huoshu

Create a small local area network subnet on the current host that is not connected to the outside world. Huoshu is the name of the network segment. When you start a docker container, you can display the specified-- net huoshu to automatically get an IP within the network segment.

It is stipulated that redis runs at 172.21.0.3, and the project configuration file no longer needs to be modified.

In a custom network environment, the port of the container and its host cannot be connected (but the default network is OK). We also need to add the following code so that the port of the host can be directly connected in the container, whether through 172.21.0.1 or the physical IP of the host.

$iptables-I INPUT_direct-s 172.21.0.0 ACCEPT2 16-j. Basic Operation of docker 2.1about save and load-methods of locally storing / copying mirrors

Generally, images are transmitted through pull/push and forwarded through image repositories. In view of Firetree's application scenario, you can save the image locally and copy it to other servers with docker environment, and you can continue to use it.

The list of images on the current system can be viewed through the docker images command, and the results are as follows.

$docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEreg01.sky-mobi.com/huoshu/redis 1.0.0 7a0e963024cf 6 hours ago 370MBreg01.sky-mobi.com/huoshu/nginx 1.0.0 99e4c2104361 7 days ago 453MBreg01.sky-mobi.com/huoshu/base 1.0.0 62925dab3a8e 7 days ago 330MB

Use the following command to package the nginx image into a tar file.

$docker save-o nginx-1.0.0.tar reg01.sky-mobi.com/huoshu/nginx:1.0.0$ lsnginx-1.0.0.tar

Copy the nginx-1.0.0.tar file to another server that has a docker environment and load it.

$docker load

< ./nginx-1.0.0.tar c97485ea5599: Loading layer [==================================================>

] 125MB/125MB834571917b0e: Loading layer [= = >] 3.584kB/3.584kBLoaded image: reg01.sky-mobi.com/huoshu/nginx:1.0.0$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEreg01.sky-mobi.com/huoshu/nginx 1.0.0 99e4c2104361 7 days ago 453MB

You can see that the image name will remain the same after * * load, so the image version number should be different when the project is upgraded, otherwise conflicts will occur.

2.2 designation of oracle addresses

It is agreed that the address of oracle in the project will be written as the domain name jdbc.oracle.addr, and then when the container that is useful to oracle is started, specify ORACLE_ADDR on the command line as the address of the actual oracle server (this can be achieved through the-e option of docker).

During the startup of the container, the address specified by the ORACLE_ADDR variable and jdbc.oracle.addr will be written to the / etc/hosts file of the container itself, and the domain name and the oracle server address can be resolved.

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