Dockerfile(例子)

创建Dockerfile

[root@demo1 ~]# vi Dockerfile 
#基于基础镜像:本例为ubuntu:last
FROM ubuntui
#RUN命令:基于基础镜像,执行命令
RUN apt-get update && apt install nginx -y && apt install vim -y
#启动时,执行的命令
CMD ["/usr/sbin/nginx","-g","daemon off;"]
~                                                     

Build镜像

[root@demo1 ~]# docker build ./ -t my-nginx:ubuntu -f Dockerfile 
Sending build context to Docker daemon  86.02kB
Step 1/3 : FROM ubuntu
latest: Pulling from library/ubuntu
ea362f368469: Pull complete 
Digest: sha256:b5a61709a9a44284d88fb12e5c48db0409cfad5b69d4ff8224077c57302df9cf
Status: Downloaded newer image for ubuntu:latest
 ---> d13c942271d6
Step 2/3 : RUN apt-get update && apt install nginx -y && apt install vim -y
 ---> Running in 313f60e501ba
Get:1 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:3 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [1385 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB]
Get:7 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [837 kB]
Get:8 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB]
Get:9 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]
Get:10 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB]
Get:11 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [790 kB]
Get:12 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [30.1 kB]
Get:13 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1814 kB]
Get:14 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [33.7 kB]
Get:15 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1118 kB]
Get:16 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [859 kB]
Get:17 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages [50.8 kB]
Get:18 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [22.1 kB]
Fetched 20.4 MB in 1min 42s (199 kB/s)
Reading package lists...

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  fontconfig-config fonts-dejavu-core iproute2 libatm1 libbsd0 libcap2
  libcap2-bin libelf1 libexpat1 libfontconfig1 libfreetype6 libgd3 libicu66
  libjbig0 libjpeg-turbo8 libjpeg8 libmnl0 libnginx-mod-http-image-filter
  libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream
  libpam-cap libpng16-16 libssl1.1 libtiff5 libwebp6 libx11-6 libx11-data
  libxau6 libxcb1 libxdmcp6 libxml2 libxpm4 libxslt1.1 libxtables12
  nginx-common nginx-core tzdata ucf
Suggested packages:

启动容器

[root@demo1 ~]# docker run --name my-nginx -p 88:80 -dit my-nginx:ubuntu
41839fd1537445b83afd06da26ba100a5a7b0bd1590310e30acfa338e452e032
[root@demo1 ~]# docker ps
CONTAINER ID   IMAGE             COMMAND                  CREATED         STATUS         PORTS                                       NAMES
41839fd15374   my-nginx:ubuntu   "/usr/sbin/nginx -g …"   3 seconds ago   Up 2 seconds   0.0.0.0:88->80/tcp, :::88->80/tcp           my-nginx
d6ad861f5846   registry          "/entrypoint.sh /etc…"   13 hours ago    Up 13 hours    0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   registry

验证

Dockerfile(例子)_第1张图片

 

你可能感兴趣的:(ubuntu,linux,debian,docker)