- Dockerfile
- 1. 结构
- 2. 指令
- 3. 创建镜像
- 4. 创建 nginx 镜像
- 5. 制作 httpd 镜像
- 5.1 创建工作目录
- 5.2 先启动一个容器,在容器中编译安装httpd操作
- 5.3 编写dockerfile
- 5.3.1 第一个dockerfile文件
- 5.3.2 第二个dockerfile文件
- 5.3.3 第三个dockerfile文件
- 5.3.4 写一个执行脚本,改dockerfile文件,第四个dockerfile文件
- 5.4 制作镜像
- 5.5 测试
- 5.6 上传
-
Dockerfile 由一行行命令语句组成,并且支持以 # 开头的注释行。
-
Docker分为四部分:
- 基础镜像信息
- 维护者信息
- 镜像操作指令
- 容器启动时默认要执⾏的指令
# This dockerfile uses the ubuntu image # VERSION 2 - EDITION 1 # Author: seancheng # Command format: Instruction [arguments / command] ... # 第⼀⾏必须指定基于的基础镜像 FROM ubuntu # 维护者信息 LABEL MAINTAINER='seancheng xianshangxian@126.com' # 镜像操作指令 RUN echo "deb http://archive.ubuntu.com/ubuntu/ raring main universe" >> /etc/apt/sources.list RUN apt-get update && apt-get install -y nginx //更新,安装 RUN echo "ndaemon off;" >> /etc/nginx/nginx.conf ndaemon off; 在前台运行 n 换行 # 容器启动时默认要执⾏的指令 CMD /usr/sbin/nginx2. 指令
- FROM
格式为 FROM或 FROM :
- LABEL MAINTAINER
格式为 LABEL MAINTAINER,指定维护者 信息
- RUN
格式为 RUN,RUN ["/bin/bash","-c","echo hello"] 在shell终端中运⾏命令,即/bin/sh -c 或 RUN ["executable","param1","param2"],RUN echo "hello worldnhello tom" > /tmp/abc && cat /tmp/abc 使⽤exec执⾏,每条RUN指令将在当前镜像基础上执⾏指定命令,并提交为新的镜像。当命令较⻓时可以使⽤ 来换⾏
- CMD
CMD ["executable","param1","param2"] 使⽤exec执⾏,推荐⽅式 CMD command param1 param2 在/bin/sh中执⾏,提供给需要交互的应⽤ CMD ["param1","param2"] 提供给ENTRYPOINT的默认参数
- EXPOSE
格式为 EXPOSE[ ...] EXPOSE 22 80 8443
- ENV
格式为 ENV。指定⼀个环境变量,会被后续RUN指令 使⽤,并在容器运⾏时保持 ENV PG_MAJOR 9.3 ENV PG_VERSION 9.3.4 RUN curl -SL http://example.com/postgres-$PG_VERSION.tar.xz | tar -xJC /usr/src/postgress && ... ENV PATH /usr/local/postgres-$PG_MAJOR/bin:$PATH
- ENTRYPOINT
ENTRYPOINT ["executable","param1","param2"] ENTRYPOINT command param1 param2(在shell中执⾏) 每个Dockerfile中只能有⼀个ENTRYPOINT ENTRYPOINT ["/usr/sbin/nginx"]
- ADD
ADD将复制指定的 到容器中的 。 其中 可以是Dockerfile所在目录的一个相对路径(文件或目录) ADD files/* /usr/src/ 可以是一个URL ADD https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz /usr/src/ 可以是一个tar文件(会自动解压为目录) ADD apr-1.7.0.tar.gz /usr/src/
- COPY
COPY复制本地主机的 (为Dockerfile所在目录的相对路径,文件或目录)为容器中的 。目标路径不存在时会自动创建 COPY files /usr/src/
- VOLUME
VOLUME ["/data"] 创建一个可以从本地主机或其他容器挂载的挂载点,一般用来存放数据库和需要保持的数据
- USER
USER 指定运行容器时的用户名或UID,后续的RUN也会使用指定用户 RUN groupadd -r postgres && useradd -r -g postgres postgres
- WORKDIR
WORKDIR /path/to/workdir 指令配置⼯作⽬录
- ONBUILD
ONBUILD [INSTRUCTION] 配置当所创建的镜像作为其他镜像的基础镜像时,所执⾏的操作指令 ONBUILD ADD files /usr/src/3. 创建镜像
-
通过docker build命令来创建镜像,基本的格式为 docker build [选项] 路径
-
例如,指定Dockerfile所在路径为/tmp/docker_builder/,并且希望⽣成镜像标签为build_repo/first_image,可以使⽤下⾯的命令
docker build -t build_repo/first_image /tmp/docker_builder/4. 创建 nginx 镜像
- 创建目录并且编写dockerfile
[root@SYL4 ~]# mkdir nginx//创建目录
[root@SYL4 ~]# cd nginx/
[root@SYL4 nginx]# touch Dockerfile
[root@SYL4 nginx]# vim Dockerfile //编写
[root@SYL4 nginx]# cat Dockerfile
FROM ubuntu
LABEL MAINTAINER "xiaoyinguhong 3066347695@qq.com"
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse" > etc/apt/sources.list &&
echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse" >> /etc/apt/sources.list &&
echo "deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse" >> /etc/apt/sources.list &&
echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse" >> /etc/apt/sources.list &&
echo "deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse" >> /etc/apt/sources.list &&
echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse" >> /etc/apt/sources.list &&
echo "deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse" >> /etc/apt/sources.list &&
echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse" >> /etc/apt/sources.list &&
apt-get update && apt-get -y install nginx &&
echo "ndaemon off;" >> /etc/nginx/nginx.conf
CMD ["/usr/sbin/nginx"] //或者/usr/sbin/nginx
[root@SYL4 nginx]#
[root@SYL4 nginx]# docker build -t nginx:2060.1 . //在当前目录下制作镜像
- CMD 和 ENTRYPOINT,创建镜像
[root@SYL4 nginx]# cat Dockerfile
FROM ubuntu
LABEL MAINTAINER "xiaoyinguhong 3066347695@qq.com"
........ 省略
apt-get update && apt-get -y install nginx
# echo "ndaemon off;" >> /etc/nginx/nginx.conf
CMD ["-g","daemon off;"]
ENTRYPOINT ["/usr/sbin/nginx"]
[root@SYL4 nginx]#
[root@SYL4 nginx]# docker build -t nginx:2060.3 .
[root@SYL4 ~]# docker run -d --name web nginx:2060.3
460f7ac5c0133b642f91ac324a2276a880a13438ad4b5cb772f983235c0e9dc8
[root@SYL4 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
460f7ac5c013 nginx:2060.3 "/usr/sbin/nginx -g …" 8 seconds ago Up 7 seconds web
[root@SYL4 ~]#
"Cmd": [
"-g",
"daemon off;"
],
"Image": "nginx:2060.3",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": [
"/usr/sbin/nginx"
- 暴露端口号,制作镜像,并访问
[root@SYL4 nginx]# cat Dockerfile
FROM ubuntu
LABEL MAINTAINER "xiaoyinguhong 3066347695@qq.com"
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse" > etc/apt/sources.list &&
......
apt-get update && apt-get -y install nginx
# echo "ndaemon off;" >> /etc/nginx/nginx.conf
EXPOSE 80 443
CMD ["-g","daemon off;"]
ENTRYPOINT ["/usr/sbin/nginx"]
[root@SYL4 nginx]#
制作镜像
[root@SYL4 nginx]# docker build -t nginx:2060.4 .
运行
[root@SYL4 ~]# docker run -d --name web1 nginx:2060.4
bdaeaf7f9d0a3f2c1e3c548d1cae9672208456a9a7fc631394e4f41b901915c4
[root@SYL4 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bdaeaf7f9d0a nginx:2060.4 "/usr/sbin/nginx -g …" 2 seconds ago Up 1 second 80/tcp, 443/tcp web1
460f7ac5c013 nginx:2060.3 "/usr/sbin/nginx -g …" 8 minutes ago Up 8 minutes web
[root@SYL4 ~]#
访问
[root@SYL4 ~]# curl 172.17.0.3
Welcome to nginx!
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.
For online documentation and support please refer to
nginx.org.
Commercial support is available at
nginx.com.
Thank you for using nginx.
[root@SYL4 ~]#
- 环境变量
[root@SYL4 nginx]# vim Dockerfile
[root@SYL4 nginx]# cat Dockerfile
FROM ubuntu
LABEL MAINTAINER "xiaoyinguhong 3066347695@qq.com"
ENV a=10
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse" > etc/apt/sources.list &&
.....
apt-get update && apt-get -y install nginx
# echo "ndaemon off;" >> /etc/nginx/nginx.conf
EXPOSE 80 443
CMD ["-g","daemon off;"]
ENTRYPOINT ["/usr/sbin/nginx"]
[root@SYL4 nginx]#
[root@SYL4 nginx]# docker build -t nginx:2060.5 .
运行容器
[root@SYL4 ~]# docker run -d --name web2 nginx:2060.5
5fcbe6f624a5032d4b8dd9cfadac893a66207739c67b8da1a900b8b9e5517d71
[root@SYL4 ~]# docker exec -it web2 /bin/bash
root@5fcbe6f624a5:/# echo $a
10
root@5fcbe6f624a5:/# bash
root@5fcbe6f624a5:/# bash
root@5fcbe6f624a5:/# echo $a
10
root@5fcbe6f624a5:/# exit
exit
root@5fcbe6f624a5:/# exit
exit
root@5fcbe6f624a5:/# exit
exit
[root@SYL4 ~]#
5. 制作 httpd 镜像
5.1 创建工作目录
[root@SYL4 ~]# mkdir httpd [root@SYL4 ~]# cd httpd [root@SYL4 httpd]# touch Dockerfile [root@SYL4 httpd]# [root@SYL4 httpd]# ls Dockerfile apr-util-1.6.1.tar.gz apr-1.7.0.tar.gz httpd-2.4.53.tar.gz [root@SYL4 httpd]# mkdir files [root@SYL4 httpd]# ls Dockerfile apr-util-1.6.1.tar.gz httpd-2.4.53.tar.gz apr-1.7.0.tar.gz files [root@SYL4 httpd]# mv *.gz files [root@SYL4 httpd]# ls Dockerfile files5.2 先启动一个容器,在容器中编译安装httpd操作
[root@SYL4 httpd]# docker run -it centos /bin/bash
[root@74e93d1c1421 /]# useradd -r -M -s /sbin/nologin apache
[root@74e93d1c1421 /]# id apache
uid=998(apache) gid=996(apache) groups=996(apache)
[root@74e93d1c1421 /]#
[root@SYL4 httpd]# docker cp files 74e93d1c1421:/usr/src/
[root@SYL4 httpd]#
解压目录
[root@74e93d1c1421 files]# tar xf apr-1.7.0.tar.gz
[root@74e93d1c1421 files]# tar xf apr-util-1.6.1.tar.gz
[root@74e93d1c1421 files]# tar xf httpd-2.4.53.tar.gz
[root@74e93d1c1421 files]# ls
apr-1.7.0 apr-util-1.6.1 httpd-2.4.53
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.53.tar.gz
[root@74e93d1c1421 files]# rm -f *.gz
[root@74e93d1c1421 files]# ls
apr-1.7.0 apr-util-1.6.1 httpd-2.4.53
[root@74e93d1c1421 files]# mv * /usr/src
[root@74e93d1c1421 files]# cd ..
[root@74e93d1c1421 src]# ls
apr-1.7.0 apr-util-1.6.1 debug files httpd-2.4.53 kernels
[root@74e93d1c1421 src]# rm -rf files
[root@74e93d1c1421 src]#
进入apr目录,编译安装apr
[root@74e93d1c1421 apr-1.7.0]# sed -n '/$RM "$cfgfile"/p' configure
$RM "$cfgfile"
[root@74e93d1c1421 apr-1.7.0]# sed -i '/$RM "$cfgfile"/d' configure
[root@74e93d1c1421 apr-1.7.0]#./configure --prefix=/usr/local/apr
[root@74e93d1c1421 apr-1.7.0]# make
[root@74e93d1c1421 apr-1.7.0]# make install
进入apr-util,编译安装
[root@74e93d1c1421 apr-1.7.0]# cd ../apr-util-1.6.1/
[root@74e93d1c1421 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@74e93d1c1421 apr-util-1.6.1]# make
[root@74e93d1c1421 apr-util-1.6.1]# make install
进入httpd,编译安装
[root@74e93d1c1421 apr-util-1.6.1]# cd ../httpd-2.4.53/
[root@74e93d1c1421 httpd-2.4.53]# ./configure --prefix=/usr/local/apache --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
[root@74e93d1c1421 httpd-2.4.53]# make
[root@74e93d1c1421 httpd-2.4.53]# make install
[root@74e93d1c1421 /]# du -sh *
5.3 编写dockerfile
5.3.1 第一个dockerfile文件
[root@SYL4 ~]# cd httpd/
[root@SYL4 httpd]# ls
Dockerfile files
[root@SYL4 httpd]# vim Dockerfile
[root@SYL4 httpd]# cat Dockerfile
FROM centos
LABEL MAINTAINER "xiaoyinguhong 3066347695@qq.com"
EXPOSE 80 443
ADD files/* /usr/src/
RUN useradd -r -M -s /sbin/nologin apache &&
rm -rf /etc/yum.repos.d/* &&
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo &&
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo &&
yum clean all &&
yum -y install openssl-devel pcre-devel expat-devel libtool make gcc gcc-c++ &&
cd /usr/src/apr-1.7.0 &&
sed -i '/$RM "$cfgfile"/d' configure &&
./configure --prefix=/usr/local/apr &&
make &&
make install &&
cd ../apr-util-1.6.1/ &&
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr &&
make &&
make install &&
cd ../httpd-2.4.53/ &&
./configure --prefix=/usr/local/apache
--enable-so
--enable-ssl
--enable-cgi
--enable-rewrite
--with-zlib
--with-pcre
--with-apr=/usr/local/apr
--with-apr-util=/usr/local/apr-util/
--enable-modules=most
--enable-mpms-shared=all
--with-mpm=prefork &&
make &&
make install
WORKDIR /usr/local/apache
CMD ["-D","FOREGROUND"]
ENTRYPOINT ["/usr/local/apache/bin/httpd"]
[root@SYL4 httpd]#
5.3.2 第二个dockerfile文件
[root@SYL4 httpd]# vim Dockerfile
[root@SYL4 httpd]# cat Dockerfile
FROM centos
LABEL MAINTAINER "xiaoyinguhong 3066347695@qq.com"
EXPOSE 80 443
ADD files/* /usr/src/
RUN useradd -r -M -s /sbin/nologin apache &&
rm -rf /etc/yum.repos.d/* &&
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo &&
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo &&
yum clean all &&
yum -y install openssl-devel pcre-devel expat-devel libtool make gcc gcc-c++ &&
cd /usr/src/apr-1.7.0 &&
sed -i '/$RM "$cfgfile"/d' configure &&
./configure --prefix=/usr/local/apr &&
make &&
make install &&
cd ../apr-util-1.6.1/ &&
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr &&
make &&
make install &&
cd ../httpd-2.4.53/ &&
./configure --prefix=/usr/local/apache
--enable-so
--enable-ssl
--enable-cgi
--enable-rewrite
--with-zlib
--with-pcre
--with-apr=/usr/local/apr
--with-apr-util=/usr/local/apr-util/
--enable-modules=most
--enable-mpms-shared=all
--with-mpm=prefork &&
make &&
make install &&
yum -y remove gcc gcc-c++ make &&
rm -rf /var/log/* /var/cache/* /usr/src/*
WORKDIR /usr/local/apache
CMD ["-D","FOREGROUND"]
ENTRYPOINT ["/usr/local/apache/bin/httpd"]
[root@SYL4 httpd]#
5.3.3 第三个dockerfile文件
[root@SYL4 httpd]# vim Dockerfile
[root@SYL4 httpd]# cat Dockerfile
FROM centos
LABEL MAINTAINER "xiaoyinguhong 3066347695@qq.com"
EXPOSE 80 443
ENV VERSION 2.4.53
ENV PATH /usr/local/apache/bin:$PATH
ADD files/apr-1.7.0.tar.gz /usr/src/
ADD files/apr-util-1.6.1.tar.gz /usr/src/
ADD https://downloads.apache.org/httpd/httpd-${VERSION}.tar.gz /usr/src/
RUN useradd -r -M -s /sbin/nologin apache &&
rm -rf /etc/yum.repos.d/* &&
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo &&
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo &&
yum clean all &&
yum -y install openssl-devel pcre-devel expat-devel libtool make gcc gcc-c++ &&
cd /usr/src &&
tar xf httpd-${VERSION}.tar.gz &&
cd /usr/src/apr-1.7.0 &&
sed -i '/$RM "$cfgfile"/d' configure &&
./configure --prefix=/usr/local/apr &&
make &&
make install &&
cd ../apr-util-1.6.1/ &&
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr &&
make &&
make install &&
cd ../httpd-${VERSION}/ &&
./configure --prefix=/usr/local/apache
--enable-so
--enable-ssl
--enable-cgi
--enable-rewrite
--with-zlib
--with-pcre
--with-apr=/usr/local/apr
--with-apr-util=/usr/local/apr-util/
--enable-modules=most
--enable-mpms-shared=all
--with-mpm=prefork &&
make &&
make install &&
yum -y remove gcc gcc-c++ make &&
rm -rf /var/log/* /var/cache/* /usr/src/*
WORKDIR /usr/local/apache
CMD ["-D","FOREGROUND"]
ENTRYPOINT ["/usr/local/apache/bin/httpd"]
[root@SYL4 httpd]#
5.3.4 写一个执行脚本,改dockerfile文件,第四个dockerfile文件
[root@SYL4 ~]# cd httpd/
[root@SYL4 httpd]# ls
Dockerfile files
[root@SYL4 httpd]# cat Dockerfile > files/install.sh
[root@SYL4 httpd]# vim files/install.sh
[root@SYL4 httpd]# cat files/install.sh
#!/bin/bash
useradd -r -M -s /sbin/nologin apache &&
rm -rf /etc/yum.repos.d/* &&
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo &&
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo &&
yum clean all &&
yum -y install openssl-devel pcre-devel expat-devel libtool make gcc gcc-c++ &&
cd /usr/src &&
tar xf httpd-${VERSION}.tar.gz &&
cd /usr/src/apr-1.7.0 &&
sed -i '/$RM "$cfgfile"/d' configure &&
./configure --prefix=/usr/local/apr &&
make &&
make install &&
cd ../apr-util-1.6.1/ &&
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr &&
make &&
make install &&
cd ../httpd-${VERSION}/ &&
./configure --prefix=/usr/local/apache
--enable-so
--enable-ssl
--enable-cgi
--enable-rewrite
--with-zlib
--with-pcre
--with-apr=/usr/local/apr
--with-apr-util=/usr/local/apr-util/
--enable-modules=most
--enable-mpms-shared=all
--with-mpm=prefork &&
make &&
make install &&
yum -y remove gcc gcc-c++ make &&
rm -rf /var/log/* /var/cache/* /usr/src/* /tmp/*
[root@SYL4 httpd]#
dockerfile 文件
[root@SYL4 httpd]# vim Dockerfile
[root@SYL4 httpd]# cat Dockerfile
FROM centos
LABEL MAINTAINER "xiaoyinguhong 3066347695@qq.com"
EXPOSE 80 443
ENV VERSION 2.4.53
ENV PATH /usr/local/apache/bin:$PATH
ADD files/apr-1.7.0.tar.gz /usr/src/
ADD files/apr-util-1.6.1.tar.gz /usr/src/
ADD https://downloads.apache.org/httpd/httpd-${VERSION}.tar.gz /usr/src/
ADD files/install.sh /tmp/
RUN /bin/bash /tmp/install.sh
WORKDIR /usr/local/apache
CMD ["-D","FOREGROUND"]
ENTRYPOINT ["/usr/local/apache/bin/httpd"]
[root@SYL4 httpd]#
5.4 制作镜像
第一个镜像 [root@SYL4 httpd]# docker build -t httpd:2060.1 . [root@SYL4 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE httpd 2060.1 1944c777af04 4 minutes ago 706MB centos latest 5d0da3dc9764 7 months ago 231MB [root@SYL4 ~]# 第二个镜像 [root@SYL4 httpd]# docker build -t httpd:2060.2 . [root@SYL4 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE httpd 2060.2 90e8433625f3 18 seconds ago 411MB httpd 2060.1 1944c777af04 21 minutes ago 706MB 第三个镜像 [root@SYL4 httpd]# docker build -t httpd:2060.3 . [root@SYL4 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE httpd 2060.3 7a446fbf6a14 11 seconds ago 379MB httpd 2060.2 90e8433625f3 28 minutes ago 411MB httpd 2060.1 1944c777af04 49 minutes ago 706MB 第四个镜像 [root@SYL4 httpd]# docker build -t httpd:2060.4 . [root@SYL4 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE httpd 2060.4 fd45f4552117 38 seconds ago 379MB httpd 2060.3 7a446fbf6a14 28 minutes ago 379MB httpd 2060.2 90e8433625f3 56 minutes ago 411MB httpd 2060.1 1944c777af04 About an hour ago 706MB5.5 测试
第一个测试 [root@SYL4 ~]# docker run -d --name web --rm httpd:2060.1 6c16897b1ad505749381b8d2b9f4d789f90758bfcb9ec3cf07a0e01438a26229 [root@SYL4 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6c16897b1ad5 httpd:2060.1 "/usr/local/apache/b…" 27 seconds ago Up 26 seconds 80/tcp, 443/tcp web 74e93d1c1421 centos "/bin/bash" 58 minutes ago Up 58 minutes friendly_mirzakhani [root@SYL4 ~]# curl 172.17.0.35.6 上传It works! [root@SYL4 ~]# 第二个测试 [root@SYL4 ~]# docker run -d --name myweb --rm xiaoyinguhong/httpd:2060.4 d049c2fa55bd2a2bf4ef8ac4b39a169747eaee885bf27af28c69c6f746ec34f0 [root@SYL4 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d049c2fa55bd xiaoyinguhong/httpd:2060.4 "/usr/local/apache/b…" 39 seconds ago Up 37 seconds 80/tcp, 443/tcp myweb 6c16897b1ad5 httpd:2060.1 "/usr/local/apache/b…" 3 hours ago Up 3 hours 80/tcp, 443/tcp web [root@SYL4 ~]# curl 172.17.0.2
It works! [root@SYL4 ~]#
[root@SYL4 ~]# docker login Authenticating with existing credentials... WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded [root@SYL4 ~]# docker tag httpd:2060.4 xiaoyinguhong/httpd:2060.4 [root@SYL4 ~]# docker push xiaoyinguhong/httpd:2060.4 The push refers to repository [docker.io/xiaoyinguhong/httpd] 12e03c99ad1d: Pushed 35565878daa0: Pushed ca9be2f85e87: Pushed bb32b11cbb88: Pushed 0b0e76572792: Pushed 74ddd0ec08fa: Layer already exists 2060.4: digest: sha256:f630e9682830bd7dd8caabdd7b9db7bcc0b2f1523b78431643977b77cd90b002 size: 1580
- 查看



