7.docker学习笔记之入门,dockercompose简单配置

编程

version: "3.6"

#设置网络环境

networks:

#自定义网络

nginx-network:

ipam:

driver: bridge

config:

- subnet: "172.16.238.0/24"

#引用外部预先定义好的网段

redis-network:

external:

name: redis-network

services:

nginx:

image: nginx

container_name: nginx-compose

environment: #设置环境变量

password: "123456"

ports:

- "8003:80"

networks:

redis-network:

ipv4_address: 192.168.1.5

volumes:

- "/usr/docker/compose/nginx/conf:/conf"

command: ["/usr/local/nginx/sbin/nginx","-c","/conf/nginx.conf","-g","daemon off;"]

privileged: true #特殊权限

working_dir: /conf #工作目录

stdin_open: true #打开标准输入

tty: true #模拟伪终端

nginx1:

build:

context: ./nginx

dockerfile: Dockerfile

args:

buildno: 1

container_name: nginx-compose2

ports:

- "8002:80"

networks:

redis-network:

ipv4_address: 192.168.1.6

volumes:

- "/usr/docker/compose/nginx/conf:/conf"

command: ["/usr/local/nginx/sbin/nginx","-c","/conf/nginx.conf","-g","daemon off;"]

docker-compose up -d #最简单的执行命令,如果没报错的话 docker images;docker ps -a 就会有对应的镜像和容器

docker-compose -p testname1 up -d #给上命名

以上是 7.docker学习笔记之入门,dockercompose简单配置 的全部内容, 来源链接: utcz.com/z/517850.html

回到顶部