1 安装
安装社区版在线安装源
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
安装docker服务
yum install docker-ce -y
2 更换docker容器在线安装源
mkdir -p /etc/docker
vim /etc/docker/daemon.json
内容
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
https://8tycmnaj.mirror.aliyuncs.com
https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
https://registry.docker-cn.com
http://hub-mirror.c.163.com
https://3laho3y3.mirror.aliyuncs.com
http://f1361db2.m.daocloud.io
https://mirror.ccs.tencentyun.com
3 常用命令
yum install net-tools -y
netstat -ntlp
//------------------------------------------
systemctl start firewalld.service
systemctl stop firewalld.service
systemctl daemon-reload
systemctl restart docker
systemctl start docker
systemctl stop docker
mv spring-boot-docker-1.0.jar ../../gzz.jar
//------------------------------------------
mvn clean
mvn package
mvn package #打包spring应用
mvn install dockerfile:build #把spring应用打成docker镜像
//------------------------------------------
docker images #查看镜像
docker run -d -p 8080:8080 <id>#运行镜像
docker run -d --name znk -p 8080:8080 znk
docker stop znk
docker rm znk
docker rmi znk
docker build -t znk .
docker logs -f -t --tail 100 znk
docker images
docker ps -a
docker export -o znk_container.tar znk
docker exec -it znk bash
docker exec -it znk /bin/sh
docker cp source.sql znk:/
4 在centos中安装好maven环境
yum install -y maven
vim /usr/share/maven/conf/settings.xml
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
5 springboot用的Dockerfile
FROM openjdk:8-jdk-alpine
# MAINTAINER gzz <gzz@163.com>
# VOLUME /tmp
ADD gzz.jar gzz.jar
ENTRYPOINT ["java","-jar","/gzz.jar"]
6 自己用的sh脚本
#!/bin/bash
cd ~
rm -rf gzz.jar
cd /root/83-spring-boot-docker
mvn clean
mvn package
mv /root/83-spring-boot-docker/target/spring-boot-docker-1.0.jar /root/gzz.jar
docker stop znk
docker rm znk
docker rmi znk
cd ~
docker build -t znk .
systemctl start firewalld
sleep 3s
docker run -d --name znk -p 8080:8080 znk
sleep 3s
systemctl stop firewalld
docker ps -a
docker images
docker logs -f -t --tail 100 znk
网友评论