3-1 dockerfile介绍

root@iZbp1berl2oy3e3vt5476fZ:~# pwd
/root
root@iZbp1berl2oy3e3vt5476fZ:~# mkdir d1
root@iZbp1berl2oy3e3vt5476fZ:~# ll
total 3700
drwx------ 11 root root    4096 Mar 22 21:05 ./
drwxr-xr-x 22 root root    4096 Mar 10 20:29 ../
-rw-------  1 root root    3309 Mar 17 01:09 .bash_history
-rw-r--r--  1 root root    3225 Mar 10 20:38 .bashrc
drwx------  4 root root    4096 Mar 10 20:54 .cache/
drwxr-xr-x  2 root root    4096 Mar 22 21:05 d1/
drwx------  3 root root    4096 Jan 28 23:04 .gnupg/
-rw-r--r--  1 root root      44 Mar 22 19:48 index.html
drwxr-xr-x  3 root root    4096 Mar 10 20:38 .local/
-rw-------  1 root root      39 Mar 10 20:35 .mysql_history
drwxr-xr-x  9 root root    4096 Mar 11 19:15 operational_tools/
-rw-r--r--  1 root root 1761815 Mar 11 19:13 operational_tools.zip
drwxr-xr-x  2 root root    4096 Jan 28 15:11 .pip/
-rw-r--r--  1 root root     148 Aug 17  2015 .profile
-rw-r--r--  1 root root     206 Mar 10 20:29 .pydistutils.cfg
-rw-r--r--  1 root root     915 Mar 10 20:40 requirements.txt
drwxr-xr-x  7 root root    4096 Mar 16 17:00 shenshou_tools/
-rw-r--r--  1 root root 1941161 Mar 16 16:59 shenshou_tools.zip
drwx------  2 root root    4096 Jan 28 07:11 .ssh/
-rw-------  1 root root    7888 Mar 22 19:48 .viminfo
drwxr-xr-x  3 root root    4096 Mar 10 20:38 .virtualenvs/
root@iZbp1berl2oy3e3vt5476fZ:~# cd d1/
root@iZbp1berl2oy3e3vt5476fZ:~/d1# ls
root@iZbp1berl2oy3e3vt5476fZ:~/d1# touch Dockerfile
root@iZbp1berl2oy3e3vt5476fZ:~/d1# ls
Dockerfile
root@iZbp1berl2oy3e3vt5476fZ:~/d1# vim Dockerfile 
root@iZbp1berl2oy3e3vt5476fZ:~/d1# cat Dockerfile 
FROM alpine:latest
MAINTAINER root
CMD echo "hello Docker 12343”
root@iZbp1berl2oy3e3vt5476fZ:~/d1# ls
Dockerfile
root@iZbp1berl2oy3e3vt5476fZ:~/d1# docker build -t hello_docker .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM alpine:latest
latest: Pulling from library/alpine
ba3557a56b15: Pull complete 
Digest: sha256:a75afd8b57e7f34e4dad8d65e2c7ba2e1975c795ce1ee22fa34f8cf46f96a3be
Status: Downloaded newer image for alpine:latest
 ---> 28f6e2705743
Step 2/3 : MAINTAINER root
 ---> Running in e63a7e69aace
Removing intermediate container e63a7e69aace
 ---> f402ba1f30e2
Step 3/3 : CMD echo "hello Docker 12343”
 ---> Running in 7b82de6d43bf
Removing intermediate container 7b82de6d43bf
 ---> 8a688aaab432
Successfully built 8a688aaab432
Successfully tagged hello_docker:latest
root@iZbp1berl2oy3e3vt5476fZ:~/d1#

查看 新生成的

docker images
扫描二维码关注公众号,回复: 12962540 查看本文章

双引号不对

root@iZbp1berl2oy3e3vt5476fZ:~/d1# docker build -t hello_docker .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM alpine:latest
latest: Pulling from library/alpine
ba3557a56b15: Pull complete 
Digest: sha256:a75afd8b57e7f34e4dad8d65e2c7ba2e1975c795ce1ee22fa34f8cf46f96a3be
Status: Downloaded newer image for alpine:latest
 ---> 28f6e2705743
Step 2/3 : MAINTAINER root
 ---> Running in e63a7e69aace
Removing intermediate container e63a7e69aace
 ---> f402ba1f30e2
Step 3/3 : CMD echo "hello Docker 12343”
 ---> Running in 7b82de6d43bf
Removing intermediate container 7b82de6d43bf
 ---> 8a688aaab432
Successfully built 8a688aaab432
Successfully tagged hello_docker:latest
root@iZbp1berl2oy3e3vt5476fZ:~/d1# docker images
REPOSITORY      TAG       IMAGE ID       CREATED             SIZE
hello_docker    latest    8a688aaab432   2 minutes ago       5.61MB
nginx-fun-hlg   latest    1d0b6ec5c36a   About an hour ago   133MB
nginx           latest    6084105296a9   10 days ago         133MB
ubuntu          latest    4dd97cefde62   2 weeks ago         72.9MB
alpine          latest    28f6e2705743   4 weeks ago         5.61MB
root@iZbp1berl2oy3e3vt5476fZ:~/d1# docker run hello_docker
/bin/sh: syntax error: unterminated quoted string
root@iZbp1berl2oy3e3vt5476fZ:~/d1# docker run hello_docker
/bin/sh: syntax error: unterminated quoted string
root@iZbp1berl2oy3e3vt5476fZ:~/d1# vim Dockerfile 
root@iZbp1berl2oy3e3vt5476fZ:~/d1# docker run hello_docker
/bin/sh: syntax error: unterminated quoted string
root@iZbp1berl2oy3e3vt5476fZ:~/d1# docker build -t hello_docker .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM alpine:latest
 ---> 28f6e2705743
Step 2/3 : MAINTAINER root
 ---> Using cache
 ---> f402ba1f30e2
Step 3/3 : CMD echo "hello Docker 1234"
 ---> Running in 7d88d71b1299
Removing intermediate container 7d88d71b1299
 ---> 71256a536e16
Successfully built 71256a536e16
Successfully tagged hello_docker:latest
root@iZbp1berl2oy3e3vt5476fZ:~/d1# docker run hello_docker
hello Docker 1234
root@iZbp1berl2oy3e3vt5476fZ:~/d1# 

成功了!

以下是全部代码:

Xshell 5 (Build 0537)
Copyright (c) 2002-2014 NetSarang Computer, Inc. All rights reserved.

Type `help' to learn how to use Xshell prompt.
[c:\~]$ 

Connecting to 118.31.36.138:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-135-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

 * Canonical Livepatch is available for installation.
   - Reduce system reboots and improve kernel security. Activate at:
     https://ubuntu.com/livepatch

Welcome to Alibaba Cloud Elastic Compute Service !

Last login: Tue Mar 16 16:58:03 2021 from 114.218.93.223
root@iZbp1berl2oy3e3vt5476fZ:~# clear
root@iZbp1berl2oy3e3vt5476fZ:~# sudo wget -qO- https://get.docker.com/| sh
# Executing docker install script, commit: 3d8fe77c2c46c5b7571f94b42793905e5b3e42e4
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
+ sh -c curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | apt-key add -qq - >/dev/null
Warning: apt-key output should not be parsed (stdout is not a terminal)
+ sh -c echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable" > /etc/apt/sources.list.d/docker.list
+ sh -c apt-get update -qq >/dev/null
+ [ -n  ]
+ sh -c apt-get install -y -qq --no-install-recommends docker-ce >/dev/null
+ sh -c docker version
Client: Docker Engine - Community
 Version:           20.10.5
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        55c4c88
 Built:             Tue Mar  2 20:18:05 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.5
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       363e9a8
  Built:            Tue Mar  2 20:16:00 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.4
  GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc:
  Version:          1.0.0-rc93
  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:

  sudo usermod -aG docker your-user

Remember that you will have to log out and back in for this to take effect!

WARNING: Adding a user to the "docker" group will grant the ability to run
         containers which can be used to obtain root privileges on the
         docker host.
         Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
         for more information.
root@iZbp1berl2oy3e3vt5476fZ:~# sudo apt-get update
Hit:1 http://mirrors.cloud.aliyuncs.com/ubuntu bionic InRelease
Hit:2 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates InRelease
Hit:3 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-security InRelease   
Hit:4 https://download.docker.com/linux/ubuntu bionic InRelease                 
Reading package lists... Done                      
root@iZbp1berl2oy3e3vt5476fZ:~# docker version
Client: Docker Engine - Community
 Version:           20.10.5
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        55c4c88
 Built:             Tue Mar  2 20:18:05 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.5
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       363e9a8
  Built:            Tue Mar  2 20:16:00 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.4
  GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc:
  Version:          1.0.0-rc93
  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
root@iZbp1berl2oy3e3vt5476fZ:~# sudo wget -qO- https://get.docker.com/| sh
# Executing docker install script, commit: 3d8fe77c2c46c5b7571f94b42793905e5b3e42e4
Warning: the "docker" command appears to already exist on this system.

If you already have Docker installed, this script can cause trouble, which is
why we're displaying this warning and provide the opportunity to cancel the
installation.

If you installed the current Docker package using this script and are using it
again to update Docker, you can safely ignore this message.

You may press Ctrl+C now to abort this script.
+ sleep 20
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
+ sh -c curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | apt-key add -qq - >/dev/null
Warning: apt-key output should not be parsed (stdout is not a terminal)
+ sh -c echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable" > /etc/apt/sources.list.d/docker.list
+ sh -c apt-get update -qq >/dev/null
+ [ -n  ]
+ sh -c apt-get install -y -qq --no-install-recommends docker-ce >/dev/null
+ sh -c docker version
Client: Docker Engine - Community
 Version:           20.10.5
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        55c4c88
 Built:             Tue Mar  2 20:18:05 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.5
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       363e9a8
  Built:            Tue Mar  2 20:16:00 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.4
  GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc:
  Version:          1.0.0-rc93
  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:

  sudo usermod -aG docker your-user

Remember that you will have to log out and back in for this to take effect!

WARNING: Adding a user to the "docker" group will grant the ability to run
         containers which can be used to obtain root privileges on the
         docker host.
         Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
         for more information.
root@iZbp1berl2oy3e3vt5476fZ:~# sudo usermod -aG docker hlg
usermod: user 'hlg' does not exist
root@iZbp1berl2oy3e3vt5476fZ:~# sudo usermod -aG docker root
root@iZbp1berl2oy3e3vt5476fZ:~# docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.5
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc version: 12644e614e25b05da6fd08a38ffa0cfe1903fdec
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 4.15.0-135-generic
 Operating System: Ubuntu 18.04.5 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 985.1MiB
 Name: iZbp1berl2oy3e3vt5476fZ
 ID: ZXLY:QXW6:OXL7:VILK:KVRB:OC4Q:XOBW:BXL7:HMD3:VOLB:IP4R:WY6J
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No swap limit support
root@iZbp1berl2oy3e3vt5476fZ:~# clear
root@iZbp1berl2oy3e3vt5476fZ:~# docker run ubuntu echo hello docker
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
5d3b2c2d21bb: Pull complete 
3fc2062ea667: Pull complete 
75adf526d75b: Pull complete 
Digest: sha256:b4f9e18267eb98998f6130342baacaeb9553f136142d40959a1b46d6401f0f2b
Status: Downloaded newer image for ubuntu:latest
hello docker
root@iZbp1berl2oy3e3vt5476fZ:~# docker run ubuntu echo hello docker
hello docker
root@iZbp1berl2oy3e3vt5476fZ:~# docker run nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
6f28985ad184: Pull complete 
29f7ebf60efd: Pull complete 
879a7c160ac6: Pull complete 
de58cd48a671: Pull complete 
be704f37b5f4: Pull complete 
158aac73782c: Pull complete 
Digest: sha256:d2925188effb4ddca9f14f162d6fba9b5fab232028aa07ae5c1dab764dca8f9f
Status: Downloaded newer image for nginx:latest
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
^Croot@iZbp1berl2oy3e3vt5476fZ:~# docker run nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
^Croot@iZbp1berl2oy3e3vt5476fZ:~# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    6084105296a9   9 days ago    133MB
ubuntu       latest    4dd97cefde62   2 weeks ago   72.9MB
root@iZbp1berl2oy3e3vt5476fZ:~# docker run -p 8080:80 -d nginx
173d54b314c146d379b2a0b53d651dd56c7ffbc068845adf97de6b34ab4b4de9
root@iZbp1berl2oy3e3vt5476fZ:~# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                  NAMES
173d54b314c1   nginx     "/docker-entrypoint.…"   2 minutes ago   Up 2 minutes   0.0.0.0:8080->80/tcp   agitated_jennings
root@iZbp1berl2oy3e3vt5476fZ:~# vim index.html
root@iZbp1berl2oy3e3vt5476fZ:~# cat index.html 
<html>
	<h1> Docker is fun 123</h1>
</html>
root@iZbp1berl2oy3e3vt5476fZ:~# docker cp index.html 173d54b314c1://usr/share/nginx/html
root@iZbp1berl2oy3e3vt5476fZ:~# docker stop 173d54b314c1
173d54b314c1
root@iZbp1berl2oy3e3vt5476fZ:~# docker run -p 8080:80 -d nginx
a3602cc5370e281dadcf807f56343b7553bc54e0b05fc302931d5cace1331f8b
root@iZbp1berl2oy3e3vt5476fZ:~# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                  NAMES
a3602cc5370e   nginx     "/docker-entrypoint.…"   3 minutes ago   Up 3 minutes   0.0.0.0:8080->80/tcp   jovial_kare
root@iZbp1berl2oy3e3vt5476fZ:~# docker cp index.html a3602cc5370e://usr/share/nginx/htm
root@iZbp1berl2oy3e3vt5476fZ:~# docker commit -m "fun hlg" a3602cc5370e
sha256:158ccdd27f63067f1196dd97b5bde1be9f47e9ee55a1993d09735d68c2c3a303
root@iZbp1berl2oy3e3vt5476fZ:~# docker images
REPOSITORY   TAG       IMAGE ID       CREATED              SIZE
<none>       <none>    158ccdd27f63   About a minute ago   133MB
nginx        latest    6084105296a9   9 days ago           133MB
ubuntu       latest    4dd97cefde62   2 weeks ago          72.9MB
root@iZbp1berl2oy3e3vt5476fZ:~# docker commit -m "fun hlg" a3602cc5370e nginx-fun-hlg
sha256:1d0b6ec5c36a8f8e1b55d9dc64fd7442e0a6a8b63361906196419cb6d84f5a84
root@iZbp1berl2oy3e3vt5476fZ:~# docker images
REPOSITORY      TAG       IMAGE ID       CREATED         SIZE
nginx-fun-hlg   latest    1d0b6ec5c36a   3 seconds ago   133MB
<none>          <none>    158ccdd27f63   3 minutes ago   133MB
nginx           latest    6084105296a9   10 days ago     133MB
ubuntu          latest    4dd97cefde62   2 weeks ago     72.9MB
root@iZbp1berl2oy3e3vt5476fZ:~# docker rmi 158ccdd27f63
Deleted: sha256:158ccdd27f63067f1196dd97b5bde1be9f47e9ee55a1993d09735d68c2c3a303
root@iZbp1berl2oy3e3vt5476fZ:~# docker images
REPOSITORY      TAG       IMAGE ID       CREATED         SIZE
nginx-fun-hlg   latest    1d0b6ec5c36a   2 minutes ago   133MB
nginx           latest    6084105296a9   10 days ago     133MB
ubuntu          latest    4dd97cefde62   2 weeks ago     72.9MB
root@iZbp1berl2oy3e3vt5476fZ:~# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                  NAMES
a3602cc5370e   nginx     "/docker-entrypoint.…"   13 minutes ago   Up 13 minutes   0.0.0.0:8080->80/tcp   jovial_kare
root@iZbp1berl2oy3e3vt5476fZ:~# docker stop a3602cc5370e
a3602cc5370e
root@iZbp1berl2oy3e3vt5476fZ:~# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
root@iZbp1berl2oy3e3vt5476fZ:~# docker ps -a
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS                          PORTS     NAMES
a3602cc5370e   nginx     "/docker-entrypoint.…"   16 minutes ago   Exited (0) About a minute ago             jovial_kare
173d54b314c1   nginx     "/docker-entrypoint.…"   30 minutes ago   Exited (0) 19 minutes ago                 agitated_jennings
9d827f501f82   nginx     "/docker-entrypoint.…"   34 minutes ago   Exited (0) 33 minutes ago                 elastic_hugle
857d94349bca   nginx     "/docker-entrypoint.…"   38 minutes ago   Exited (0) 34 minutes ago                 eloquent_ganguly
fb0eb55c9b8b   ubuntu    "echo hello docker"      41 minutes ago   Exited (0) 41 minutes ago                 adoring_dirac
72d47427e376   ubuntu    "echo hello docker"      42 minutes ago   Exited (0) 42 minutes ago                 serene_wescoff
root@iZbp1berl2oy3e3vt5476fZ:~# docker rm fb0eb55c9b8b
fb0eb55c9b8b
root@iZbp1berl2oy3e3vt5476fZ:~# docker ps -a
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS                      PORTS     NAMES
a3602cc5370e   nginx     "/docker-entrypoint.…"   18 minutes ago   Exited (0) 3 minutes ago              jovial_kare
173d54b314c1   nginx     "/docker-entrypoint.…"   33 minutes ago   Exited (0) 21 minutes ago             agitated_jennings
9d827f501f82   nginx     "/docker-entrypoint.…"   37 minutes ago   Exited (0) 35 minutes ago             elastic_hugle
857d94349bca   nginx     "/docker-entrypoint.…"   41 minutes ago   Exited (0) 37 minutes ago             eloquent_ganguly
72d47427e376   ubuntu    "echo hello docker"      44 minutes ago   Exited (0) 44 minutes ago             serene_wescoff
root@iZbp1berl2oy3e3vt5476fZ:~# docker run -p 8080:80 -d nginx
ae4a8e6d3a00455d43c37805cf069561d6bcaa161a3e08c1e942d58ff291cfd4
root@iZbp1berl2oy3e3vt5476fZ:~# docker ps -a
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS                      PORTS                  NAMES
ae4a8e6d3a00   nginx     "/docker-entrypoint.…"   19 seconds ago   Up 17 seconds               0.0.0.0:8080->80/tcp   nifty_babbage
a3602cc5370e   nginx     "/docker-entrypoint.…"   21 minutes ago   Exited (0) 6 minutes ago                           jovial_kare
173d54b314c1   nginx     "/docker-entrypoint.…"   35 minutes ago   Exited (0) 24 minutes ago                          agitated_jennings
9d827f501f82   nginx     "/docker-entrypoint.…"   39 minutes ago   Exited (0) 38 minutes ago                          elastic_hugle
857d94349bca   nginx     "/docker-entrypoint.…"   43 minutes ago   Exited (0) 39 minutes ago                          eloquent_ganguly
72d47427e376   ubuntu    "echo hello docker"      47 minutes ago   Exited (0) 47 minutes ago                          serene_wescoff
root@iZbp1berl2oy3e3vt5476fZ:~# clear
root@iZbp1berl2oy3e3vt5476fZ:~# pwd
/root
root@iZbp1berl2oy3e3vt5476fZ:~# mkdir d1
root@iZbp1berl2oy3e3vt5476fZ:~# ll
total 3700
drwx------ 11 root root    4096 Mar 22 21:05 ./
drwxr-xr-x 22 root root    4096 Mar 10 20:29 ../
-rw-------  1 root root    3309 Mar 17 01:09 .bash_history
-rw-r--r--  1 root root    3225 Mar 10 20:38 .bashrc
drwx------  4 root root    4096 Mar 10 20:54 .cache/
drwxr-xr-x  2 root root    4096 Mar 22 21:05 d1/
drwx------  3 root root    4096 Jan 28 23:04 .gnupg/
-rw-r--r--  1 root root      44 Mar 22 19:48 index.html
drwxr-xr-x  3 root root    4096 Mar 10 20:38 .local/
-rw-------  1 root root      39 Mar 10 20:35 .mysql_history
drwxr-xr-x  9 root root    4096 Mar 11 19:15 operational_tools/
-rw-r--r--  1 root root 1761815 Mar 11 19:13 operational_tools.zip
drwxr-xr-x  2 root root    4096 Jan 28 15:11 .pip/
-rw-r--r--  1 root root     148 Aug 17  2015 .profile
-rw-r--r--  1 root root     206 Mar 10 20:29 .pydistutils.cfg
-rw-r--r--  1 root root     915 Mar 10 20:40 requirements.txt
drwxr-xr-x  7 root root    4096 Mar 16 17:00 shenshou_tools/
-rw-r--r--  1 root root 1941161 Mar 16 16:59 shenshou_tools.zip
drwx------  2 root root    4096 Jan 28 07:11 .ssh/
-rw-------  1 root root    7888 Mar 22 19:48 .viminfo
drwxr-xr-x  3 root root    4096 Mar 10 20:38 .virtualenvs/
root@iZbp1berl2oy3e3vt5476fZ:~# cd d1/
root@iZbp1berl2oy3e3vt5476fZ:~/d1# ls
root@iZbp1berl2oy3e3vt5476fZ:~/d1# touch Dockerfile
root@iZbp1berl2oy3e3vt5476fZ:~/d1# ls
Dockerfile
root@iZbp1berl2oy3e3vt5476fZ:~/d1# vim Dockerfile 
root@iZbp1berl2oy3e3vt5476fZ:~/d1# cat Dockerfile 
FROM alpine:latest
MAINTAINER root
CMD echo "hello Docker 12343”
root@iZbp1berl2oy3e3vt5476fZ:~/d1# ls
Dockerfile
root@iZbp1berl2oy3e3vt5476fZ:~/d1# docker build -t hello_docker .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM alpine:latest
latest: Pulling from library/alpine
ba3557a56b15: Pull complete 
Digest: sha256:a75afd8b57e7f34e4dad8d65e2c7ba2e1975c795ce1ee22fa34f8cf46f96a3be
Status: Downloaded newer image for alpine:latest
 ---> 28f6e2705743
Step 2/3 : MAINTAINER root
 ---> Running in e63a7e69aace
Removing intermediate container e63a7e69aace
 ---> f402ba1f30e2
Step 3/3 : CMD echo "hello Docker 12343”
 ---> Running in 7b82de6d43bf
Removing intermediate container 7b82de6d43bf
 ---> 8a688aaab432
Successfully built 8a688aaab432
Successfully tagged hello_docker:latest
root@iZbp1berl2oy3e3vt5476fZ:~/d1# docker images
REPOSITORY      TAG       IMAGE ID       CREATED             SIZE
hello_docker    latest    8a688aaab432   2 minutes ago       5.61MB
nginx-fun-hlg   latest    1d0b6ec5c36a   About an hour ago   133MB
nginx           latest    6084105296a9   10 days ago         133MB
ubuntu          latest    4dd97cefde62   2 weeks ago         72.9MB
alpine          latest    28f6e2705743   4 weeks ago         5.61MB
root@iZbp1berl2oy3e3vt5476fZ:~/d1# docker run hello_docker
/bin/sh: syntax error: unterminated quoted string
root@iZbp1berl2oy3e3vt5476fZ:~/d1# docker run hello_docker
/bin/sh: syntax error: unterminated quoted string
root@iZbp1berl2oy3e3vt5476fZ:~/d1# vim Dockerfile 
root@iZbp1berl2oy3e3vt5476fZ:~/d1# docker run hello_docker
/bin/sh: syntax error: unterminated quoted string
root@iZbp1berl2oy3e3vt5476fZ:~/d1# docker build -t hello_docker .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM alpine:latest
 ---> 28f6e2705743
Step 2/3 : MAINTAINER root
 ---> Using cache
 ---> f402ba1f30e2
Step 3/3 : CMD echo "hello Docker 1234"
 ---> Running in 7d88d71b1299
Removing intermediate container 7d88d71b1299
 ---> 71256a536e16
Successfully built 71256a536e16
Successfully tagged hello_docker:latest
root@iZbp1berl2oy3e3vt5476fZ:~/d1# docker run hello_docker
hello Docker 1234
root@iZbp1berl2oy3e3vt5476fZ:~/d1# 

猜你喜欢

转载自blog.csdn.net/huanglianggu/article/details/115097929
3-1