安装Docker: yum install docker 查看docker 版本 docker --version 启动服务 systemctl start docker.service

添加阿里云加速器:

vim /etc/docker/daemon.json 内容为:

{
    "registry-mirrors":["https://your-own-address.mirror.aliyuncs.com"]
}

编辑Dockerfile

# docker file for dubbo-admin-tomcat
# VERSION 0.1
# Author: chenziqiang

# basic image
FROM tomcat:8.5-jre8

# author
MAINTAINER chenziqiang <czq@itczq.com>

# env
ENV BIN_PATH /usr/local/tomcat/bin
ENV APP_PATH /usr/local/tomcat/webapps
ENV CONF_PATH /usr/local/tomcat/conf
ENV LOG_PATH /usr/local/tomcat/logs
ENV SERVER_CONF_FILE server.xml
ENV USER_CONF_FILE tomcat-users.xml

# delete origin config files
RUN rm $CONF_PATH/$USER_CONF_FILE
RUN rm -rf $APP_PATH/*

# add war to image
ADD ./dubbo-admin.war /root
RUN unzip /root/dubbo-admin.war -d $APP_PATH/ROOT/
RUN rm -rf /root/dubbo-admin.war

# replace dubbo conf file
RUN rm $APP_PATH/ROOT/WEB-INF/dubbo.properties
ADD ./dubbo.properties $APP_PATH/ROOT/WEB-INF/

# run
ENTRYPOINT $BIN_PATH/startup.sh && tail -F $LOG_PATH/catalina.out

相关Docker命令: 创建镜像:

docker build -t dubbo-admin-tomcat:0.1 --rm=true .

列出镜像

docker images

如果要删除镜像,要先停止容器、删除容器,再删除镜像:

查看有哪些容器在运行 docker ps

删除容器 docker rm $container_id

删除镜像 docker rmi $image_id

运行容器: docker run -d -p 8000:8080 ${image_id} 说明:8000是宿主机端口,8080是映射到docker容器内的tomcat端口

进入容器 docker exec -it $container_id /bin/sh