Docker-build-900x551.png

安装docker

curl -fsSL https://get.docker.com | bash -s docker --mirror aliyun

安装compose

需要注意版本

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

启动docker

sudo systemctl start docker

Docker Swarm

docker swarm init
docker swarm join-token manager

创建用于portainer的docker-compose.yml

mkdir portainer_data
version: "3.6"
services:
    tc-portainer:
        container_name: portainer
        image: portainer/portainer:latest
        restart: always
        ports:
          - 9000:9000
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock:rw
            - /root/portainer_data:/data:rw
        logging:
            driver: "json-file"
            options:
                max-size: "10m"

注意修改对应的文件存储路径。

启动portainer

docker-compose up -d

配置镜像加速地址

配置之前,在pull mysql镜像时报错:

[root@VM-16-7-centos ~]# docker pull mysql
Using default tag: latest
Error response from daemon: Get https://registry-1.docker.io/v2/: read tcp 172.17.16.7:48514->54.161.109.204:443: read: connection reset by peer
[root@VM-16-7-centos ~]# curl https://registry-1.docker.io/v2/
curl: (35) TCP connection reset by peer

故配置镜像加速:

 vim /etc/docker/daemon.json
{
  "registry-mirrors": ["http://hub-mirror.c.163.com", "https://{aliyunid}.mirror.aliyuncs.com"]
}

以上配置的是两个镜像地址,一个是网易,一个是阿里云,阿里云的镜像加速地址,需要在阿里云控制台获取。