docker-compose样例


Join the chat at https://gitter.im/simpleyyt/jekyll-theme-next

networks

  • 创建新的网络
docker network create --driver=bridge --subnet=172.33.0.0/24 test_net

对比 docker-compose方式

networks:
    test_net:
        driver: bridge
        ipam:
            driver: default
            config:
             - subnet: 172.33.0.0/24

lnmp

version: '3'
services:
    nginx:
        image: nginx
        container_name: lnmp-nginx
        depends_on:
         - php
        ports:
         - "5008:80"
        networks:
         - "test_net"
        volumes:
         - ./conf.d/site.conf:/etc/nginx/conf.d/default.conf
         - ./www:/www
        links:
         - php:php
    php:
        image: php:5.6-fpm
        container_name: lnmp-php
        expose: 
         - 9000
        networks:
         - "test_net"
        volumes:
         - "./www:/www"
networks:
    test_net:
        driver: bridge
        ipam:
            driver: default
            config:
                - subnet: 172.32.0.0/24

mysql

docker run -p 3002:3306 --name mysql3302 -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6

对比 docker-compose

version: "3"

services:
    mysql1:
        image: mysql:5.6
        volumes:
         - ./data1:/var/lib/mysql
         - ./conf1:/etc/mysql
         - ./logs1:/logs
        container_name: mysql1
        ports:
         - 3303:3306
        environment:
            TZ: Asia/Shanghai
            MYSQL_ROOT_PASSWORD: 123456
        command:
            --character-set-server=utf8mb4
            --max_allowed_packet=32M
        networks:
         - mysql_net
    mysql2:
        image: mysql:5.6
        volumes:
         - ./data2:/var/lib/mysql
         - ./conf2:/etc/mysql
         - ./logs2:/logs
        container_name: mysql2
        ports:
         - 3304:3306
        environment:
            TZ: Asia/Shanghai
            MYSQL_ROOT_PASSWORD: 123456
        command:
            --character-set-server=utf8mb4
            --max_allowed_packet=32M
        networks:
         - mysql_net

networks:
    mysql_net:
        driver: bridge
        ipam:
            config:
                - subnet: 172.55.0.0/24

build

  • Dockerfile-app
FROM alpine:latest

RUN echo -e "http://mirrors.ustc.edu.cn/alpine/v3.7/main\n\
http://mirrors.ustc.edu.cn/alpine/v3.7/community" > /etc/apk/repositories

RUN apk --update add curl bash openjdk8-jre-base && \
      rm -rf /var/cache/apk/*


ENV JAVA_HOME /usr/lib/jvm/default-jvm
ENV PATH ${PATH}:${JAVA_HOME}/bin
  • docker-compose-java.yml
version: '3'
services:
    app:
        build:
            context: /data/alpine-java
            dockerfile: Dockerfile-java
  • 运行 docker-compose -f docker-compose-java.yml build

文章作者: SakuraGaara
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 SakuraGaara !
 上一篇
docker-compose模板文件主要命令 docker-compose模板文件主要命令
docker-compose主要命令及功能 命令 功能 build 指定Dockerfile所在文件的路径 cap_add, cap_drop 指定容器的内核能力capacity分配 command 覆盖容器启动
2019-02-20
下一篇 
Docker网络 Docker网络
mount 命令查看挂载信息 /etc/hosts, /etc/hostname, /etc/resolve.conf 是临时的,只是在运行容器时保留,docker commit不会被提交 root@gitlab:/# mount |gr
2019-02-15
  目录