docker的应用

WuYiLong原创大约 1 分钟dockerdocker

docker 配置运行nginx

docker-compose -f nginx.yml up -d
内容如下:
nginx:
  image: nginx:latest
  ports:
    - "8082:83"
  volumes: 
    - ./nginx/www:/usr/share/nginx/html
    - ./nginx/conf/default.conf:/etc/nginx/conf.d/default.conf

docker 配置运行mysql,mongo,redis

docker-compose -f docker-compose.yml up -d

version: "3.7"
services:
  mongo:
    image: mongo:latest
    ports:
      - "27017:27017"
    volumes: 
      - ./mongo:/data/db 
  redis:
    image: redis:latest
    ports:
      - "6379:6379"
  mysql:
    image: mysql:latest
    volumes:
      - ./mysql:/var/lib/mysql
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: "root"

在centos上安装docker

// 卸载残留
sudo yum remove docker docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
 

sudo yum remove docker-ce docker-ce-cli containerd.io
// 设置仓库
先安装依赖包
sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

// 添加稳定仓库
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
// 安装 docker
sudo yum install docker-ce docker-ce-cli containerd.io
//启动
sudo systemctl start docker


// 因为原目录空间不大,所以在空间大的磁盘创建目录

mkdir /data/docker

mkdir /etc/systemd/system/docker.service.d

vi /etc/systemd/system/docker.service.d/devicemapper.conf

// 写入内容

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --graph=/data/docker

// 重启docker

systemctl daemon-reload
systemctl restart docker
//设置docker开机自启
systemctl enable docker
// 确定没问题后,删除原目录 rm -rf /var/lib/docker

在centos上安装 docker-compose

 curl -L https://github.com/docker/compose/releases/download/1.24.0-rc1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

// 设置docker-compose可执行
sudo chmod +x /usr/local/bin/docker-compose 

// 查看docker-compose是否安装成功
docker-compose --version
上次编辑于:
贡献者: wuyilong