root@ubuntu:~# cd /dockerfile/df_test4/

root@ubuntu:/dockerfile/df_test4# vim Dockerfile

root@ubuntu:/dockerfile/df_test4#cat Dockerfile

# 设置基本的镜像,后续命令都以这个镜像为基础 

FROM ubuntu

# 作者信息 

MAINTAINER shangwu 

# RUN命令会在上面指定的镜像里执行任何命令 

RUN apt-get update

RUN apt-get install -y nginx

 

#暴露ssh端口

EXPOSE 80 

ENTRYPOINT ["/usr/sbin/nginx","-g", "daemon off;"]

 

root@ubuntu:/dockerfile/df_test4#

root@ubuntu:/dockerfile/df_test4#docker build -t="df_test4" .

Sending build context to Docker daemon 2.048 kB

Sending build context to Docker daemon

Step 0 : FROM ubuntu

 --->dc8dd8718e57

Step 1 : MAINTAINER shangwu

 --->Using cache

 --->cd3d00722426

Step 2 : RUN apt-get update

 --->Using cache

 --->0096fe9ac7c4

Step 3 : RUN apt-get install -y nginx

 --->Using cache

 --->c8b93cc747d7

Step 4 : EXPOSE 80

 --->Using cache

 --->266559c6bc7f

Step 5 :ENTRYPOINT /usr/sbin/nginx -g daemon off;

 --->Running in ff1c83947cd7

 --->112ebc020e4e

Removing intermediate container ff1c83947cd7

Successfully built 112ebc020e4e

root@ubuntu:/dockerfile/df_test4#

 

root@ubuntu:/dockerfile/df_test4#docker images

REPOSITORY              TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

df_test4                latest              112ebc020e4e        14 seconds ago      214.3 MB

df_test3                latest              ea94d0b70edb        41 minutes ago      214.3 MB

df_test2                latest              33bc74414c04        About an hour ago   214.3 MB

ubuntu-nginx-df_test2   latest              266559c6bc7f        9 hours ago         214.3 MB

ubuntu-nginx            v1                  8377a82bd88d        9 hours ago         232.8 MB

ubuntu                 latest              dc8dd8718e57        10 days ago         119.2 MB

root@ubuntu:/dockerfile/df_test4#docker run -p 80 -d --name ep_test1 df_test4 /bin/bash

8fc88f1f1ec1711528087a518c68460a2222f753d011ae1be3208b44b9ee5e0b

root@ubuntu:/dockerfile/df_test4#docker ps -l

CONTAINER ID       IMAGE               COMMAND                CREATED             STATUS                     PORTS               NAMES

8fc88f1f1ec1       df_test4:latest    "/usr/sbin/nginx -g    5seconds ago       Exited (1) 5 secondsago                       ep_test1           

root@ubuntu:/dockerfile/df_test4#

说明:

       1)可以看到/bin/bash命令没有覆盖ENTRYPOINT中的命令;

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐