Docker & Compose安装以及入门

Docker 安装

脚本安装

  • 自定义脚本

    wget https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm
    yes | yum localinstall docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm
    systemctl start docker
    # add aliyun accelarater
    touch /etc/docker/daemon.json
    cat>>/etc/docker/daemon.json<<EOF 
    {
        "insecure-registries" : ["0.0.0.0/0"],
        "registry-mirrors": ["https://4wmjwi37.mirror.aliyuncs.com"],
        "log-driver": "json-file",
        "log-opts": {
            "max-size": "10m",
            "max-file": "3"
        }
    }
    EOF
    systemctl daemon-reload
    systemctl restart docker
    docker info
    
  • docker社区

    curl -sSL https://get.docker.com | sh
    docker -v
    
  • 阿里云脚本

    curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
    docker -v
    
  • daocloud脚本

    curl -sSL https://get.daocloud.io/docker | sh
    docker -v
    

配置加速器

  • 阿里云

    sudo mkdir -p /etc/docker
    sudo tee /etc/docker/daemon.json <<-'EOF'
    {
      "registry-mirrors": ["https://dist7hw1.mirror.aliyuncs.com"]
    }
    EOF
    sudo systemctl daemon-reload
    sudo systemctl restart docker
    docker info
    
  • DaoCloud

    curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://ced808ab.m.daocloud.io
    
    sudo systemctl restart docker
    
    docker info
    
    

卸载 Docker

  • 卸载脚本

    #sudo apt-get remove docker docker-engine docker.io
    yum remove docker \
    				  docker-client \
    				  docker-client-latest \
    				  docker-common \
    				  docker-latest \
    				  docker-latest-logrotate \
    				  docker-logrotate \
    				  docker-selinux \
    				  docker-engine-selinux \
    				  docker-engine
    
    rpm -qa | grep docker | xargs yum remove
    
    rm -rf /etc/systemd/system/docker.service.d
    
    rm -rf /var/lib/docker
    
    rm -rf /var/run/docker
    
    

Docker Compose安装

二进制包安装(推荐)

  • 官网
    https://github.com/docker/compose/releases

  • 安装脚本

    sudo curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
    sudo chmod +x /usr/local/bin/docker-compose
    sudo docker-compose -v
    
  • 卸载脚本

    sudo rm -rf /usr/local/bin/docker-compose
    

PIP 安装

#pip -V
#安装 python-pip
yum -y install epel-release
yum -y install python-pip
pip install --upgrade pip
pip -V
sudo pip install -U docker-compose
docker-compose -version

docker-compose 案例

version: '3'
services:
  # ref:https://hub.docker.com/_/mysql
  # ref:https://docs.docker.com/samples/library/mysql/#-via-docker-stack-deploy-or-docker-compose
  mysql:
    image: mysql:8.0
    container_name: mysql
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    # data 用来存放了数据库表文件,init存放初始化的脚本
    volumes:
      - ./mysql/data/:/var/lib/mysql/
      - ./mysql/conf/my.cnf:/etc/my.cnf
      - ./mysql/init:/docker-entrypoint-initdb.d/
    restart: always
    ports:
      - "3306:3306"
      - "33060:33060"
    environment:
      TZ: Asia/Shanghai
      MYSQL_ROOT_PASSWORD: root123
      MYSQL_USER: dev
      MYSQL_PASSWORD: dev123
  consul:
    image: consul
    container_name: consul
    command: agent -dev -client 0.0.0.0 -log-level info
    restart: always
    ports:
      - "8500:8500"
  rabbitmq:
    image: rabbitmq:management-alpine
    container_name: rabbitmq
    environment:
      - RABBITMQ_DEFAULT_USER=dev
      - RABBITMQ_DEFAULT_PASS=dev123
    restart: always
    ports:
      - "15672:15672"
      - "5672:5672"
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"
  redis:
    image: redis
    container_name: redis
    command: redis-server /usr/local/etc/redis/redis.conf
    restart: always
    ports:
      - "6379:6379"
    volumes:
      - ./redis/data:/data
      - ./redis/redis.conf:/usr/local/etc/redis/redis.conf

说明

Compose file format Docker Engine
1 1.9.0+
2.0 1.10.0+
2.1 1.12.0+
2.2, 3.0, 3.1, 3.2 1.13.0+
2.3, 3.3, 3.4, 3.5 17.06.0+
2.4 17.12.0+
3.6 18.02.0+
3.7 18.06.0+

Docker常用命令

  • 查看系列

    镜像:docker images -a

    容器 :docker ps -a

    进入容器:docker exec -it 容器Id /bin/bash

常用Docker软件安装教程

posted @ 2019-07-11 20:24  kancy  阅读(676)  评论(0编辑  收藏  举报