centos 8 install Docker-compose, Docker

Install Docker
automatically using the official installation script.
The installation command is as follows:

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
can also use the domestic daocloud one-click installation command:

curl -sSL https://get.daocloud.io/docker | sh
Set the warehouse
The mirror warehouse is responsible for the storage and distribution of mirror content. In simple terms, it is a platform for users to download various software.
Install the required packages. yum-utils provides yum-config-manager, and the device mapper storage driver requires device-mapper-persistent-data and lvm2.

$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

Use the following commands to set up mirror repositories for different websites.

official source

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

Aliyun

$ sudo yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

Tsinghua University source

$ sudo yum-config-manager \
    --add-repo \
    https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

install Docker Engine-Community
sudo yum install docker -ce docker-ce-cli containerd.io --allowerasing

installation command can choose parameters –allowerasing, –skip-broken or –nobest, if there are no these parameters, an exception will be prompted:

Try adding '--allowerasing' to the command line to replace conflicting packages or '--skip-broken' to skip packages that cannot be installed or '--nobest' to not only use the best candidate for a package to install
successfully Then enter the command to start docker, as shown below

sudo systemctl start docker
 

install docker on centos 8

1. The previous version of Yuzai

yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate dokcer-logrotate docker-engin

Yuzai docker-ce (ce stands for community version)

yum remove docker-ce docker-ce-cli containerd.io

delete docker resource

rm -rf /var/lib/docker

2. Install dependent packages

yum install -y yum-utils

3. Set the mirror warehouse (the default is a foreign warehouse, the download is very slow)

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

4. Update yum

yum makecache

5. Install docker

yum install docker-ce docker-ce-cli containerd.io

If you don't want to install the latest version of docker, but want to install a specified version, you can do this:

First check out what versions of docker there are

yum list docker-ce --showduplicates | sort -r

Install the specified version

sudo yum install docker-ce-<version_string> docker-ce-cli-<version_string> containerd.io

For example, to install version 18.09.1:

sudo yum install docker-ce-18.09.1 docker-ce-cli-18.09.1 containerd.io

6. Start docker

sudo systemctl start docker

Check whether the startup is successful

docker version

7. Start docker automatically when booting

systemctl enable docker

8. Run Hello-world image

sudo docker run hellow-world

 docker version information:

 

 Run hello-world information:

9. Configure the docker image accelerator

Apply for a container mirror service in the Alibaba Cloud console, and then a mirror accelerator address [https://qiby9901.mirror.aliyuncs.com] will be assigned.
If you have not applied for the Alibaba Cloud Mirror Accelerator, do not configure the daemon.json file. The accelerator can only be accessed on the Alibaba Cloud server intranet.
Create a daemon.json file in the /etc/docker directory.

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://qiyb9901.mirror.aliyuncs.com"
]
}
EOF

Save, reload configuration file and restart docker

sudo systemctl daemon-reload
sudo systemctl restart docker

10. Install docker visual interface management tool portainer

docker run -d -p 8090:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer

Note that the docker container port must be 9000 to start portainer

Enter in the browser address bar: http://local ip:8090 to access portainer.

Install docker-compose on centos 8

[Step 1] Install docker compose 

(1) Download and install docker-compose from a foreign server

Foreign server download address and installation instructions: Install Docker Compose | Docker Documentation

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

 The official service is abroad, and the download is very slow. It is recommended to download from the domestic server.  

(2) Download and install docker-compose from the domestic server

Domestic server download address and installation instructions: https://get.daocloud.io

curl -L https://get.daocloud.io/docker/compose/releases/download/v2.2.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

You can customize the version you need by modifying the version in the URL.

Downloading to the /usr/local/bin directory is the installation. Grant execute permission after the download is complete.

Check whether the download is successful.

ll /usr/local/bin

[Step 2] Verify whether the installation is successful

Verify that docker-compose is installed successfully:

docker-compose --version

 

[Step 3] Uninstall Docker-Compose

rm /usr/local/bin/docker-compose

docker-compose common commands

Get help for a command 
docker-compose command --help 

builds and starts all containers, and rebuilds if the image exists 
docker-compose up -d --build 

starts all services 
docker-compose up -d 

build starts the nignx container                
docker-compose up -d nginx        

-f specifies the Compose configuration file to start. The default is docker-compose.yml, which can be specified multiple times. 
docker-compose -f docker-compose.yml up -d 

run a service and execute a command on the service 
docker-compose run container id or container name ip addr 

log in to the nginx container              
docker-compose exec nginx bash 

this command will Stop the container started by the up command and remove the network 
docker-compose down 

lists all running containers in the project 
docker-compose ps 

lists all running and non-running containers in the project 
docker-compose ps -a 

lists all running service containers 
docker-compose ls 

lists all service containers (including non-running ones)
docker-compose ls -a 

restart nginx container 
docker-compose restart nginx           

build image           
docker-compose build nginx             

build without cache        
docker-compose build --no-cache nginx      

view the processes running in each service container       
docker-compose top               

view nginx’s real-time log                
docker-compose logs -f nginx         

lists the images contained in the Compose file            
docker-compose images 

to verify the file configuration. When the configuration is correct, nothing is output. When the file configuration is incorrect, an error message is output.                         
docker-compose config                 

outputs the docker log of nginx in the form of json            
docker-compose events --json nginx         

pause nignx container      
docker-compose pause nginx         

Restore the ningx container             
docker-compose unpause nginx       

to delete the container (the container must be closed before deleting, execute stop)              
docker-compose rm nginx                        

forcefully delete the container (the container does not need to be closed first)              
docker-compose rm -f nginx     

stop the nignx container          
docker-compose stop nginx        
    
start nignx container            
docker-compose start nginx      

restart nignx container in the project                 
docker-compose restart nginx                

download dependent image 
docker-compose pull push    

service depends on the image 
docker-compose push 

setting specifies the number of containers that the service runs. Set the number through the parameter of service=num 
docker-compose scale web=3 db=2 

view version information 
docker-compose version

 

Guess you like

Origin blog.csdn.net/u010258235/article/details/127257579