1.Docker安装部署
(1).关闭防火墙
(2).更新源

(3)设置Docker仓库





(4)启动docker

(5)查看版本:

2.Docker pull 容器并运行服务;
拉取nginx镜像,运行该nginx实例

访问 web 页面 192.168.16.16:8080
docker ps
docker exec -it efe8484c1ca2 /bin/bash

更换镜像阿里源
echo "">sources.list
echo "deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib">>sources.list
echo "deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib">>sources.list
echo "deb http://mirrors.aliyun.com/debian-security stretch/updates main">>sources.list
echo "deb-src http://mirrors.aliyun.com/debian-security stretch/updates main">>sources.list
echo "deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib">>sources.list echo "deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib">>sources.list echo "deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib">>sources.list echo "deb-src http://mirrors.aliyun.com/debian/ stretch-backports main nonfree contrib">>sources.list
echo "deb https://deb.debian.org/debian buster main contrib nonfree">>sources.list
echo "deb-src https://deb.debian.org/debian buster main contrib nonfree">>sources.list
echo "deb https://deb.debian.org/debian buster-updates main contrib nonfree">>sources.list
echo "deb-src https://deb.debian.org/debian buster-updates main contrib nonfree">>sources.list echo "deb https://deb.debian.org/debian buster-backports main contrib nonfree">>sources.list
echo "deb-src https://deb.debian.org/debian buster-backports main contrib non-free">>sources.list 更新源 apt-get update
安装 vim apt-get install vim

修改 index.html 为自己的学号和姓名(https://registry.hub.docker.com/_/nginx)
cd /usr/share/nginx/html


3.Dockerfile和Docker build定制容器;dockerfile内容显示,docker build过程截图
拉取镜像、编写 dockerfile
docker pull ubuntu:16.04
mkdir baseos
cd baseos
touch Dockerfile
vi Dockerfile
Base os image FROM ubuntu:16.04
MAINTAINER your_name <your_email_address>
LABEL Description="This image is the base os images." Version="1.0"
reconfig timezone
RUN echo "Asia/Shanghai" > /etc/timezone


docker build -t chenzhiyong/baseos:1.0 .
docker images

构建 jre 基础镜像
下载 jdk,解压,将文件中的 jre 打包
sudo mv jre jre1.8.0_321
sudo tar -zcvf jre-8u321-linux-x64.tar.gz jre1.8.0_321
sudo mkdir jre-8u321 sudo cp jre-8u321-linux-x64.tar.gz jre-8u321
cd jre-8u321/
sudo vi Dockerfile
Base jre image
FROM xjli/baseos:1.0
MAINTAINER your_name
LABEL Description="This image is used to serve Oracle jre 7u80" Version="1.0"
Install and config Oracle jre
ADD jre-8u321-linux-x64.tar.gz /usr/lib/jvm/
RUN update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jre1.8.0_321/bin/java" 1 \
&& update-alternatives --set java /usr/lib/jvm/jre1.8.0_321/bin/java
ENV JAVA_HOME /usr/lib/jvm/jre1.8.0_321



构建 jre 镜像
docker build -t xjli/jre:8u321 .
检查版本 --rm 选项可以在容器运行完毕立即删除容器。
docker run --rm xjli/jre:8u321 java -version

构建 tomcat 基础镜像
mkdir tomcat7-jre7
cp apache-tomcat-7.0.77.tar.gz tomcat7-jre7/
cd tomcat7-jre7/
vi Dockerfile
Base image
FROM xjli/jre:8u321
MAINTAINER your_name <your_email_address>
LABEL Description="This image is used to run tomcat7 with jre7." Version="1.0"
#把 tomcat 添加到容器中
ADD apache-tomcat-7.0.77.tar.gz /usr/local
ENV CLASSPATH JAVA_HOME/lib/dt.jar:JAVA_HOME/lib/tools.jar
#配置 tomcat 环境变量
ENV CATALTNA_HOME /usr/local/apache-tomcat-7.0.77
ENV PATH PATH:JAVA_HOME/bin:$CATALTNA_HOME/bin
#设置工作目录
WORKDIR $CATALTNA_HOME
#容器端口
EXPOSE 8080 ENTRYPOINT ["catalina.sh","run"]

docker build -t xjli/tomcat:7-jre7 .
docker run -d --name mytomcat1 -p 10086:8080 xjli/tomcat:7-jre7 container:2d044b41600f

