1.安装docker compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
2.给docker-compose执行权限
sudo chmod 777 /usr/local/bin/docker-compose
3.查看docker-compose版本信息
docker-compose --version
4.编写docker-compose文件
docker-compose.yml version: '3' services: wordpress: image: wordpress ports: - 8080:80 environment: WORDPRESS_DB_HOST: mysql WORDPRESS_DB_PASSWORD: root networks: - my-bridge mysql: image: mysql environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: wordpress volumes: - mysql-data:/var/lib/mysql networks: - my-bridge volumes: mysql-data: networks: my-bridge: driver: bridge version: '3' services: redis: image: redis web: build: context: . dockerfile: Dockerfile ports: - 8080:5000 environment: REDIS_HOST: redis
5.执行docker-compose文件
docker-compose up -d(后台执行) 或 docker-compose -f docker-compose.yml up -d(后台执行)
6.docker-compose基础操作
1.查看状态 docker-compose ls 2.停止 docker-compose stop 或 docker-compose down # down会删除容器 数据卷 镜像 等 3.启动 docker-compose start 4.查看docker-compose里面定义的container docker-compose images 5.进入docker-compose定义的container docker-compose exec -it mysql(container名称) /bin/bash