Installation and basic use of native docker under CentOS

System version: CentOS7

The network is configured as bridged

Virtualization software VMware

Docker-ce installation

turn off firewall

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# systemctl disable firewalld

Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.

Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

modify hostname

[root@localhost ~]# hostnamectl set-hostname docker01

[root@localhost ~]# bash

Configure yum source

Add software source information (the source of Alibaba Cloud is used here)

[root@docker01 ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

[root@docker01 ~]# cd /etc/yum.repos.d/

[root@docker01 yum.repos.d]# ls

CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo

CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo  docker-ce.repo

Generate cache (optional)

[root@docker01 yum.repos.d]# yum makecache fast

download docker-ce

[root@docker01 yum.repos.d]# yum -y install docker-ce

Start docker and set it to start automatically at boot

[root@docker01 yum.repos.d]# systemctl start docker

[root@docker01 yum.repos.d]# systemctl enable docker

Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

Since the docker mirror warehouse is abroad, the download speed will be very slow, so replace it with a domestic one

Enter Alibaba Cloud, search for the container image service, click on the image tool, and the image accelerator will generate a unique accelerator address for you.

[root@docker01 yum.repos.d]# mkdir -p /etc/docker

[root@docker01 yum.repos.d]# tee /etc/docker/daemon.json <<-'EOF'

> {

>   "registry-mirrors": ["https://zo590uqq.mirror.aliyuncs.com"]

> }

> EOF

{

  "registry-mirrors": ["https://zo590uqq.mirror.aliyuncs.com"]

}

[root@docker01 yum.repos.d]# systemctl daemon-reload

[root@docker01 yum.repos.d]# systemctl restart docker

run the first container

Pull the image ( if no version is specified, the default is latest )

[root@docker01 yum.repos.d]# docker pull nginx

view mirror

[root@docker01 yum.repos.d]# docker images

REPOSITORY   TAG       IMAGE ID       CREATED       SIZE

nginx        latest    605c77e624dd   3 weeks ago   141MB

create a container

[root@docker01 yum.repos.d]# docker create --name web1 nginx

7dc823897732b0489235ae5ddd0da89ac687dd30f6c71b056de535010cd75b1a

view container

[root@docker01 yum.repos.d]# docker ps -a

run container

[root@docker01 yum.repos.d]# docker start id
delete container

[root@docker01 yum.repos.d]# docker rm -f id

The above steps to create and run the container can use a command

[root@docker01 system]# docker run -d -p 8088:80 --name web03 httpd

-d puts the container in the background

-p specifies port mapping

--name specifies the container name

into the container

 [root@docker01 system]# docker exec -i -t id /bin/bash

 

 The kernel and cpu resources of the container use the host machine, but it does not have an operating system, so it is lighter than a virtual machine. Generally, the configured files will be copied to the container for running, but you can also enter the container for operation

Copy the host's files to the root directory of the container

[root@docker01 ~]# docker cp /etc/passwd   id:/

Enter an nginx container and perform a simple website editing operation

root@a72082edb06a:/etc# cat /etc/issue
Debian GNU/Linux 11 \n \l
root@a72082edb06a:/etc# apt-get upgate
root@a72082edb06a:/etc# apt-get install vim
root@a72082edb06a:/etc# cd /usr/share/nginx/html/
root@a72082edb06a:/usr/share/nginx/html# ls
50x.html  index.html
root@a72082edb06a:/usr/share/nginx/html# echo hellow word > index.html 
root@a72082edb06a:/usr/share/nginx/html# 
在本地主机上访问nginx服务

 You can see that the service is accessed normally.

Guess you like

Origin blog.csdn.net/qq_53086187/article/details/122590513