docker-compose
一、安装
docker国内的镜像安装:http://get.daocloud.io/
查询官网是1.24.0版本:https://docs.docker.com/compose/install/
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose # 授权
docker-compose version # 查询版本或者安装情况
二、编写docker-compose.yml文件
version: '3' #version是3和docker-compose的version一样
services:
web:
restart: always
image: tomcat
container_name: web
ports:
- 8080:8080
volumes: #服务器和容器路径映射
- /usr/local/docker/myshop/ROOT:/usr/local/tomcat/webapps/ROOT
mysql:
restart: always
image: mysql
container_name: mysql
ports:
- 3306:3306
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: 123456
MYSQL_USER: 'test'
MYSQL_PASS: 'yourpassword'
command:
--character-set-server=utf8mb4
--collation-server=utf8_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
--max_allowed_packet=128M
--sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO"
volumes:
- mysql-data:/var/lib/mysql
volumes:
mysql-data:
三、使用
docker-compose up # 启动容器
docker-compose up -d # 启动容器后台运行
docker-compose down # 停止容器
docker-machine
网址:https://github.com/docker/machine/releases/
安装:https://docs.docker.com/machine/install-machine/
docker-compose网络
#创建一个名字为kexianjun_network的网络 网段是172.10.0.x的,目的是为了让所有微服务都运行在此局域网内
docker network create --subnet=172.10.0.0/24 kexianjun_network
docker-compose 和Dockerfile 启动dev或者prod项目
1.Dockerfile文件编写
FROM anapsix/alpine-java
MAINTAINER kexianjun
#设置时区
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' >/etc/timezone
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} /app/app.jar
WORKDIR /app
RUN bash -c 'touch /app.jar'
EXPOSE 8080
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom", "-jar", "./app.jar"]
2.docker-compose编写
version: '3'
services:
zuul:
restart: always
image: 192.168.10.10:5000/zuul
container_name: zuul
#这里设置启动的项目
environment:
- spring.profiles.active=prod
ports:
- 8080:8080
networks:
default:
ipv4_address: 172.10.0.65
networks:
default:
external:
name: kexianjun_network