1、安装docker&docker-compose
安装docker
yum install docker-ce
验证安装
docker --version
启动docker
systemctl start docker
安装docker-compose
curl -L "https://github.com/docker/compose/releases/download/1.28.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
添加文件权限
sudo chmod +x /usr/local/bin/docker-compose
验证安装
docker-compose --version
- docker启动会出现的问题
docker启动失败: Failed to start Docker Application Container Engine 解决办法:关闭防火墙和关闭selinux 1、systemctl disable firewalld 2、setenforce 0 3、systemctl start docker 4、systemctl enable docker
2、Mysql docker-compose.yml
version: '3'
services:
db:
image: mysql:5.7
container_name: xsydb
restart: always
ports:
- 3306:3306
volumes:
- ./data/mysql:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: "123456"
MYSQL_USER: 'root'
MYSQL_PASS: '123456'
networks:
default:
external:
name: xsynet
编辑好后直接在当前目录下敲docker-compose up -d即可
2、服务docker-compose.yml(新弄一个目录放)
version: '3'
services:
xsy-bridge:
image: xsy-bridge:latest
container_name: xsy-bridge
restart: always
environment:
MYSQL_URL: jdbc:mysql://localhost:3306
MYSQL_USERNAME: root
MYSQL_PASSWORD: 123456
LOG_PATH: /logs
ENV: prod
volumes:
- /home/xsy/logs:/logs
ports:
- '8080:8080'
networks:
default:
external:
name: xsynet
4、Dockerfile (服务镜像生成文件)
FROM frolvlad/alpine-java:jdk8-slim
MAINTAINER xxx@qq.com
VOLUME /usr/data
ADD 你的jar包名 app.jar
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' >/etc/timezone
EXPOSE 8080
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"]
5、redeploy.sh (一键启动脚本)
if [ -e /tmp/itbasecli-starter-1.0.0-SNAPSHOT.jar ]; then
mv /tmp/itbasecli-starter-1.0.0-SNAPSHOT.jar ./
fi
docker-compose down
docker rmi xsy-bridge:latest
docker build ./ -t xsy-bridge:latest
docker-compose up -d
|