Docker & docker-compose安装

docker

1.docker国内访问下载速度太慢, 借用第三方 DaoCloud 提供的docker安装源

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

2.安装完成后, 使用 docker info 查看docker状态, 但是需要使用sudo权限, 因为docker命令属于docker用户组, 为了避免每次输入命令需要带sudo, 可将当前用户加入docker组

sudo gpasswd -a $(whoami) docker

3.配置镜像加速

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

docker-compose

1.docker-compose存放在github上, 安装速度不太理想, 还是借用 DaoCloud 提供的docker-compose安装源

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

2.常用docker-compose

.env:
DCOMPOSE_DIR=/data/dcompose

MYSQL_ROOT_PASSWORD=123456
docker-compose.yml:(自动加载同目录下的.env)
version: "3"
services:
  mysql:
    image: mysql:5.7
    container_name: mysql
    restart: on-failure:3
    environment:
      # 环境变量
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
    volumes:
      - "${DCOMPOSE_DIR}/mysql/data:/var/lib/mysql"
      - "${DCOMPOSE_DIR}/mysql/conf.d:/etc/mysql/conf.d"
    ports:
      - 3306:3306

  tengine:
    image: axizdkr/tengine:2.3.2
    container_name: tengine
    restart: on-failure:3
    environment:
      - TZ=Asia/Shanghai
      - LANG=zh_CN.UTF-8
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ${DCOMPOSE_DIR}/tengine/conf.d/:/etc/nginx/conf.d/
      - ${DCOMPOSE_DIR}/tengine/log/:/var/log/nginx/

你可能感兴趣的:(docker,ubuntu)