docker-compose(win7)

1.在DockerToolbox安装目录下创建两个文件夹
docker-compose(win7)_第1张图片
image.png
2.安装docker-compose
#1
curl -L https://github.com/docker/compose/releases/download/1.20.1/docker-compose-`uname -s`-`uname -m` > /compose
#2
chmod +x /compose
#查看版本信息
docker-compose -version

3.在test文件夹下创建docker-compose.yml

3.1 docker中存在镜像

image: docker中已存在镜像


docker-compose(win7)_第2张图片
image.png
3.2 使用build

当docker没有springbootdemo镜像时,可以读取DockerFile内容创建镜像,同时生产容器sboot01

docker-compose(win7)_第3张图片
image.png

3.3配置文件详解:

https://www.jianshu.com/p/2217cfed29d7
http://www.docker.org.cn/dockerppt/114.html

4.运行

docker-compose up

docker-compose.yml例子

    redis: 
        image: redis:latest
        ports: 
            - "6379:6379"
        volumes: 
            - /mbp/redis/redis.conf:/etc/redis/redis.conf
            - /mbp/redis/data:/data
        command: redis-server /etc/redis/redis.conf
    mysql: 
        image: mysql:latest
        ports: 
            - "3306:3306"
        volumes: 
            - /mbp/mysql/data:/data/mysql/data
            - /mbp/mysql/base:/var/lib/mysql
            - /mbp/mysql/mysql.cnf:/etc/mysql/my.cnf
        environment: 
            - MYSQL_ROOT_PASSWORD=root
    forecast_gaode: 
        build: /mbp/forecast_gaode
        ports: 
            - "8180:9080"
        volumes: 
            - /mbp/forecast_gaode/logs/:/mbp/reits/logs/
    forecast_yuexiu: 
        build: /mbp/forecast_yuexiu
        ports: 
            - "8280:9080"
        volumes: 
            - /mbp/forecast_yuexiu/logs/:/mbp/reits/logs/
    ree1: 
        image: ree:latest
        ports: 
            - "8001:9068"
    ree2: 
        image: ree:latest
        ports: 
            - "8002:9068"
    ree3: 
        image: ree:latest
        ports: 
            - "8003:9068"
    ree4: 
        image: ree:latest
        ports: 
            - "8004:9068"
    nginx_ree: 
        image: nginx:latest
        ports: 
            - "8000:8000"
        volumes: 
            - /mbp/ree/nginx.conf:/etc/nginx/nginx.conf
            
    nginx_gaode_lan: 
        image: nginx:latest
        ports: 
            - "8110:80"
        volumes: 
            - /mbp/nginx_gaode/dist/:/etc/nginx/html/
            - /mbp/nginx_gaode/nginx.conf:/etc/nginx/nginx.conf
            - /mbp/nginx_gaode/serverconfig_lan.json:/etc/nginx/html/serverconfig.json
    nginx_gaode_wlan: 
        image: nginx:latest
        ports: 
            - "8100:80"
        volumes: 
            - /mbp/nginx_gaode/dist/:/etc/nginx/html/
            - /mbp/nginx_gaode/nginx.conf:/etc/nginx/nginx.conf
            - /mbp/nginx_gaode/serverconfig_wlan.json:/etc/nginx/html/serverconfig.json
    nginx_yuexiu_lan: 
        image: nginx:latest
        ports: 
            - "8210:80"
        volumes: 
            - /mbp/nginx_yuexiu/dist/:/etc/nginx/html/
            - /mbp/nginx_yuexiu/nginx.conf:/etc/nginx/nginx.conf
            - /mbp/nginx_yuexiu/serverconfig_lan.json:/etc/nginx/html/serverconfig.json
    nginx_yuexiu_wlan: 
        image: nginx:latest
        ports: 
            - "8200:80"
        volumes: 
            - /mbp/nginx_yuexiu/dist/:/etc/nginx/html/
            - /mbp/nginx_yuexiu/nginx.conf:/etc/nginx/nginx.conf
            - /mbp/nginx_yuexiu/serverconfig_wlan.json:/etc/nginx/html/serverconfig.json
    nginx_test1: 
        image: nginx:latest
        ports: 
            - "8300:80"
        volumes: 
            - /mbp/nginx_test1/dist/:/etc/nginx/html/
            - /mbp/nginx_test1/nginx.conf:/etc/nginx/nginx.conf
    nginx_test2: 
        image: nginx:latest
        ports: 
            - "8400:80"
        volumes: 
            - /mbp/nginx_test2/dist/:/etc/nginx/html/
            - /mbp/nginx_test2/nginx.conf:/etc/nginx/nginx.conf
    nginx_proxy:
       image: nginx:latest
       ports: 
           - "80:80"
       links:
           - forecast_yuexiu
       volumes:
           - /mbp/nginx_proxy/nginx.conf:/etc/nginx/nginx.conf
    nginx_datacheck: 
        image: nginx:latest
        ports: 
            - "7200:80"
        volumes: 
            - /mbp/nginx_datacheck/dist/:/etc/nginx/html/
            - /mbp/nginx_datacheck/nginx.conf:/etc/nginx/nginx.conf
    nginx_demo_new_saas_front: 
        image: nginx:latest
        ports: 
            - "7201:80"
        volumes: 
            - /mbp/nginx_demo_new_saas_front/dist/:/etc/nginx/html/
            - /mbp/nginx_demo_new_saas_front/nginx.conf:/etc/nginx/nginx.conf            
        

dockerFile示例

FROM registry.cn-hangzhou.aliyuncs.com/xm123-ubuntu/sshjdk8
MAINTAINER    xuming123
LABEL description="默认端口为9080"

ADD reits-forecast.jar app.jar
RUN bash -c 'touch /app.jar'

#修改时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

#监听端口
EXPOSE 9080

#启动docker自动运行jar包
ENTRYPOINT ["java","-jar","/app.jar"]

你可能感兴趣的:(docker-compose(win7))