This is the 14th day of my participation in the August More Text Challenge. For details, see: August More Text Challenge
1. Preparation
Personal learning habits, using the virtual machine to operate, so I changed the corresponding computer name and set the static IP address
(1) Change the /etc/hostname file to the computer name
Run the following command: vi /etc/hostname Use the x key on the keyboard to delete all contents one by one. Then use the I key to enter the edits state. Enter the computer name (without adding the domain name)Copy the code
(2) Modify /etc/sysconfig/network-scripts/ifcfg-ens33
Enter the command: Run the following command to open the ENS33 configuration page: vi /etc/sysconfig/network-scripts/ifcfg-ens33 // Open the ENS33 configuration page. Use the I key on the keyboard to enter the edable state, and modify the content as follows: ----- BOOTPROTO="static" // Modify: 4.3 IPADDR="192.168.213.20" // Added: 4.4 NETMASK=" 255.XXX.xxx.xxx "// Added: Configuring the Subnet Mask 4.5 GATEWAY=" XXX.XXX.xxx.xxx" // Added: Configuring the Gateway 4.6 DNS1=" XXX.XXX.XXX.xxx "// Added: Configure DNS ----- Esc or Ctrl+ C // Exit the file editing mode :wq // Save the file changes and exit -----. Run the service network restart commandCopy the code
(3) Modify the /etc/hosts file and add a line to the file
Run the vi /etc/hosts command. Move the cursor to the line following 127.0.0.1 localhost. Run the I command to insert content. 192.168.213.20 centos7-docker centos7-docker indicates the name of the computer. After the centos7-docker is changed, run the :wq command to save and exitCopy the code
2. Install Docker
Docder official documentation -Centos installation
(1) Remove the existing Docker version. If you have not installed Docker, you can ignore this step
$sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
Copy the code
(2) Log in to the Centos as user root. Make sure your yum package is up to date.
yum update
Copy the code
(3) Install the required packages, yum-util provides the yum-config-manager function, the other two devicemapper driver depends on
yum install -y yum-utils device-mapper-persistent-data lvm2
Copy the code
(4) Configure the yum source
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
Copy the code
(5) You can view all Docker versions in all repositories, and select a specific version to install
yum list docker-ce --showduplicates | sort -r
Copy the code
(6) Install Docker, because the repo only opens stable repository by default, so here install the latest stable version 20.10.1
yum install docker-ce docker-ce-cli containerd.io -y
Copy the code
# yum install
# ym install docker-ce-17.12.0.ce
(7) Start and add boot
systemctl start docker
systemctl enable docker
Copy the code
(8) Verify whether the installation is successful (client and service two parts indicate that the docker installation and startup are successful)
Docker version or use docker --versionCopy the code
3. Configure the domestic mirror source
After the default installation of Docker, the image on Docker Hub is accessed by default when the image is pulled by the command Docker. In the domestic network environment, the download time is long, so the domestic image warehouse must be configured.
I’m using 163’s open source mirror accelerator
(1) Create or edit daemon.json
vi /etc/docker/daemon.json
Copy the code
(2) Edit the content in daemon.json
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]}Copy the code
(3) Restart Docker
// Optional command systemctl daemon-reload ----- systemctl restart docker.service // or systemctl restart dockerCopy the code
(4) Check whether the modification is successful
docker info
Copy the code
(5) The address of the accelerator in China
1. Netease http://hub-mirror.c.163.com 2. Official Docker Image in China https://registry.docker-cn.com 3. https://docker.mirrors.ustc.edu.cn 4 China university of science and technology. Ali cloud container service https://cr.console.aliyun.com/ home page, click on the "create my container mirror" to get an exclusive image of accelerating address, similar to the "https://XXXXXXXX.mirror.aliyuncs.com"Copy the code
4. Mirror command
4.1 Local Image Management
Images are stored in /var/lib/docker on the Docker host
- Listing local mirrors:
docker images
Docker images [Parameter] Parameter description: -a: lists all local images (including the middle image layer) -q: displays only the image ID. Running result description 1. 5. Size: indicates the size of the mirrorCopy the code
- Deleting a local mirror:
docker rmi
Docker rmi [Parameter] [Image name or image name list] The parameters are described as follows: -f: forcibly delete an image for example: Docker rmi-f tomcat hell-world (delete tomcat and Hell-world, default is latest without TAG) Docker rmi-f $(docker images-qa) Delete all imagesCopy the code
4.2 Remote Warehouse
- Look up images from Docker Hub:
docker search
Docker search [Parameter] Image name Parameters are described as follows: -s: Lists images whose favorites are at least the specified value. Automated: Lists only the images of the Automated build type. Example: Docker search -s 10 nginxCopy the code
- Pull or update the specified image from the image store:
docker pull
Docker pull [Parameter] Image name [:TAG] The parameters are described as follows: -a: pull all images for example: Docker pull nginx docker pull -a nginx REPOSITORYCopy the code
- Uploading an Image (tentative)
1. Configure aliyun's mirror accelerator, as described above; Docker login --username=XXX registry.cn-hangzhou.aliyuncs.com 3. Add a tag to the local image, XXX for namespace docker tag f4ec85e8298f registry.cn-hangzhou.aliyuncs.com/XXX/mynginx:0.1 4. Push the docker warehouse docker push Registry.cn-hangzhou.aliyuncs.com/XXX/mynginx:0.1 5. Log in ali cloud view the uploaded image list: https://cr.console.aliyun.com/#/imageListCopy the code
4.3 Container Operations
- List the running containers:
docker ps
Docker ps [Parameter] The parameters are described as follows: -a: displays all containers, including those that are not running. -q: displays only container numbersCopy the code
- Create a new container and run a command:
docker run
Docker run [parameter] Image name /ID [command] [Command parameter... The parameters are described as follows: -i: runs the container in interactive mode. It is usually used together with -t (be careful). -t: reallocates a pseudo input terminal to the container. --name="my": specifies a name for the container; -p: specifies a port mapping. The format is: Host (host) port: container port; -p: random port mapping. The internal ports of the container are randomly mapped to the high-end ports of the host. -d: running the container in the background; Docker run-it --name= myCentos7 centos:7 /bin/bash 2 Docker run -di --name=mycentos centos:7 /bin/bash docker exec -it mycentos /bin/bash docker run -p 8080:8080 tomcatCopy the code
- Exit the container (run as IT)
Method 1: Exit docker and docker container stops running. Mode 2: CTRL + P + Q to exit Docker, docker container continues to run.Copy the code
- Running/stopping/restarting a container:
docker start/stop/restart
Docker Start Container ID [container ID... Docker stop docker stop Docker restart Container ID [container ID...] : Restart the container The above operations must be based on the container has been created, that is, the docker run command has been executedCopy the code
You can use the systemctl status docker command to check the running status, and the systemctl enable docker command is used to set the system to start at startup
- Execute a command in a running container:
docker exec
Docker exec [parameter] container ID [command parameter... Parameter description: -d: runs in the background. -i: interactive. -t: indicates the distribution terminal. Example: docker exec -t mynginx /bin/bashCopy the code
- Kill a running container:
docker kill
Docker kill [parameter] container [container... Parameter description: -s: Sends a signal to the container. Example: docker kill -s kill mynginxCopy the code
- To delete a container:
docker rm
Docker rm [parameter] Parameter description: -f: forcibly delete docker rm -f mynginx docker rm $(docker ps -aq)Copy the code
- To obtain the container log:
docker logs
Docker logs [parameter] The container parameters are described as follows: -t: displays the timestamp. -f: output trace logs. --tail: Lists only the latest N container logs. For example: Docker logs --since="2016-07-01" --tail=10 docker logs --since="2016-07-01" --tail=10 mynginxCopy the code
- View the process information running in the container:
docker top
Docker top image example: Docker top MynginxCopy the code
- Create a new image from the container:
docker commit
Docker commit [parameter] Container [image [:TAG]] Parameter description: -a: image author; -c: Use the Dockerfile command to create the image. -m: description at the time of submission; Example: docker commit -a "hanpang" -m "create mynginx" a404c6c174a2 mynginx:v1 Run Docker images to view the created images.Copy the code
- Used to copy data between a container and a host:
docker cp
Docker CP container: source path Destination path Docker CP Source path Container: destination path Example: Docker cp /usr/abc 96f7f14e99ab:/hou/ Copy /usr/abc to 96f7f14e99ab Rename it to hou docker cp /usr/abc 96f7f14e99ab:/hou Copy the/ABC directory of container 96f7f14e99ab to the/TMP directory of the host docker cp 96f7f14e99ab:/ ABC/TMP /Copy the code
do