1.安装
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
systemctl enable docker.service
sudo docker run hello-world
1.1 换国内镜像
vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://bv8f9l6o.mirror.aliyuncs.com"]
}
systemctl restart docker.service
2.制作linux centos7v2镜像
docker pull centos:centos7
docker run -itd -p 10022:22 --name master --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup:ro centos:centos7 /usr/sbin/init
docker exec -it master bash
yum install -y net-tools.x86_64
yum install -y vim*
yum install -y openssh-server
vim/etc/ssh/sshd_config
PermitRootLogin yes
yum install initscripts -y
service sshd restart
passwd
docker commit -a "luyu" -m "v2" master centos:centos7v2
3.制作centos7-jre8镜像
下载server-jre-8u201-linux-x64.tar.gz
编辑Dockerfile
FROM centos:centos7v2
COPY server-jre-8u201-linux-x64.tar.gz /usr/java/server-jre-8u201-linux-x64.tar.gz
RUN tar -zxvf /usr/java/server-jre-8u201-linux-x64.tar.gz -C /usr/java
RUN rm /usr/java/server-jre-8u201-linux-x64.tar.gz
ENV JAVA_HOME=/usr/java/jdk1.8.0_201
ENV PATH=$JAVA_HOME/bin:$PATH
ENV CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
docker build -t centos:centos7-jre8 .
4.部署java服务
下载源码到编译路径
编译
编辑Dockerfile
FROM centos:centos7-jre8
RUN mkdir /kool
RUN mkdir /kool/soft
RUN mkdir /kool/soft/eops
RUN mkdir /kool/soft/eops/config
RUN mkdir /kool/soft/eops/proglog
COPY config/application.properties /kool/soft/eops/config/application.properties
COPY eops_init.sql /kool/soft/eops/eops_init.sql
COPY eops-0.0.1-SNAPSHOT.jar /kool/soft/eops/eops-0.0.1-SNAPSHOT.jar
COPY config/log4j2-spring.xml /kool/soft/eops/config/log4j2-spring.xml
COPY restart.sh /kool/soft/eops/restart.sh
RUN chmod +x /kool/soft/eops/restart.sh
COPY init_start.sh /etc/profile.d/init_start.sh
COPY init_start.sh /etc/init.d/init_start.sh
RUN chmod +x /etc/init.d/init_start.sh
RUN chkconfig --add init_start.sh
RUN chkconfig init_start.sh on
docker build -t eops:v1 .
导出镜像,导入到宿主机
docker run -itd -p 10022:22 -p 10101:10101 --name master --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup:ro eops:v1 /usr/sbin/init
docker exec -it master bash
网友评论