建 docker-compose 文件
volumes中掛載的目錄當宿主機不存在時,會自動建立html
vi docker-compose.yml
version: "2" # 使用Version 2
services: # 包含須要操做的容器
web1: # 容器的名稱
image: nginx # 指定基於哪一個鏡像
ports: # 指定映射的端口mysql
- "8080:80"
networks: # 指定使用哪一個網絡模式
- "net1"
volumes: # 指定掛載的的目錄
- /data/www:/usr/share/nginx/html
web2:
image: nginx
ports:
- "8081:80"
networks:
- "net2"
volumes:
- /data/www1:/usr/share/nginx/html
networks:
net1:
driver: bridge
net2:
driver: bridge
docker-compose文件內容區域nginx
查看容器狀態
[root@mysql1 opt]# docker-compose ps
Name Command State Ports
opt_web1_1 nginx -g daemon off; Up 0.0.0.0:8080->80/tcp
opt_web2_1 nginx -g daemon off; Up 0.0.0.0:8081->80/tcpdocker
[root@mysql1 opt]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f959c27eb8b0 nginx "nginx -g 'daemon of…" 4 seconds ago Up 3 seconds 0.0.0.0:8081->80/tcp opt_web2_1
60e8f1e1ba90 nginx "nginx -g 'daemon of…" 4 seconds ago Up 3 seconds 0.0.0.0:8080->80/tcp 網絡
向web掛載目錄添加內容
echo "webweb" > /data/www/index.html
echo "web11111" > /data/www1/index.html
app
查看容器狀態
[root@mysql1 opt]# docker-compose ps
Name Command State Ports
opt_web1_1 nginx -g daemon off; Up 0.0.0.0:8080->80/tcp
opt_web2_1 nginx -g daemon off; Up 0.0.0.0:8081->80/tcp
中止已有的容器:
[root@server ~]# docker-compose stop
Stopping root_app1_1 ... done
Stopping root_app2_1 ... done
[root@server ~]#
啓動已有的容器:
[root@server ~]# docker-compose start
Starting app2 ... done
Starting app1 ... done
[root@server ~]#
查看容器的狀態:
[root@server ~]# docker-compose ps
Name Command State Ports
root_app1_1 /bin/sh -c /usr/local/ngin ... Exit 137
root_app2_1 tail -f /etc/passwd Exit 137
[root@server ~]#
刪除容器:
[root@server ~]# docker-compose rm -f
Going to remove root_app1_1, root_app2_1
Removing root_app1_1 ... done
Removing root_app2_1 ... done
[root@server ~]#
中止並刪除運行中的容器:
[root@server ~]# docker-compose down
Stopping root_app1_1 ... done
Stopping root_app2_1 ... done
Removing root_app1_1 ... done
Removing root_app2_1 ... done
Removing network root_net2
Removing network root_net1
[root@server ~]# docker-compose ps
Name Command State Ports
部署MySQL5.7
vi docker-compose.yml
version: '3'
services:
mysql-server:
hostname: mysql-server
container_name: mysql-server
image: mysql:5.7
ports:tcp
- 3306:3306
networks:
- "net3"
volumes:
- /data/mysql5721/data:/var/lib/mysql
command: --character-set-server=utf8
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix
networks:
net3:
driver: bridge
進入MySQL查看
OKide