Introduction: Common Docker commands and explanations

Keywords: Linux Nginx Docker Mac OS X

I. Container Life Cycle Management

1. create

Command Interpretation: Create a container, but do not start. The container name is mynginx

leoheng-MacBook-Pro:~ leo$ docker create --name mynginx   nginx:latest
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
a5a6f2f73cd8: Pull complete 
1ba02017c4b2: Pull complete 
33b176c904de: Pull complete 
Digest: sha256:5d32f60db294b5deb55d078cd4feb410ad88e6fe77500c87d3970eca97f54dba
Status: Downloaded newer image for nginx:latest
3a9e561b7629c6880c776a9331dcc9d052685f08c98f58c940e1a164c1f8d77c
leoheng-MacBook-Pro:~ leo$ 

2. run

Command Interpretation: Create a container and run it
Optional parameters:
- a stdin: specify the standard input and output content type, and select STDIN/STDOUT/STDERR three items;
- d: Run the container in the background and return the container ID;
- i: Running containers in interactive mode, usually in conjunction with - t;
- p: Port mapping in the form of host (host) port: container port
- t: To reassign a pseudo-input terminal for the container, usually in conjunction with-i;
name="mynginx": specify a name for the container;
- dns 8.8.8.8: The DNS server used by the specified container is the same as the host by default;
- dns-search example.com: Specify the container DNS search domain name, which is the same as the host by default;
- h "leo": specify the host name of the container;
- e username="uleo": Set environment variables;
- env-file=[]: Read environment variables from the specified file;
- cpuset="0-2" or - cpuset="0,1,2": bind the container to run on the specified CPU;
- m: Set the maximum memory used by the container;
- net="bridge": specify the network connection type of container, support bridge/host/none/container: four types;
--link=[]: Add a link to another container;
Expo=[]: Open a port or a group of ports;

leoheng-MacBook-Pro:~ leo$ docker run -it -d -p 222:22 -p 8080:80 --restart=always  --name nginx nginx:latest
feea481119cb053e84bf3bda6f1b29beaddb3f91899f4d28775c4015f0dafa2f
leoheng-MacBook-Pro:~ leo$ docker ps –a #View container processes
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                                       NAMES
feea481119cb        nginx:latest        "nginx -g 'daemon of…"   About a minute ago   Up About a minute   0.0.0.0:222->22/tcp, 0.0.0.0:8080->80/tcp   nginx
leoheng-MacBook-Pro:~ leo$

3. start/stop/restart

Command Interpretation: Start, Close, Restart Containers

leoheng-MacBook-Pro:~ leo$ docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                       NAMES
feea481119cb        nginx:latest        "nginx -g 'daemon of…"   3 minutes ago       Up 3 minutes        0.0.0.0:222->22/tcp, 0.0.0.0:8080->80/tcp   nginx
leoheng-MacBook-Pro:~ leo$ docker stop feea481119cb
feea481119cb
leoheng-MacBook-Pro:~ leo$ docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
leoheng-MacBook-Pro:~ leo$ docker restrat feea481119cb
docker: 'restrat' is not a docker command.
See 'docker --help'
leoheng-MacBook-Pro:~ leo$ docker restart feea481119cb
feea481119cb
leoheng-MacBook-Pro:~ leo$ docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                       NAMES
feea481119cb        nginx:latest        "nginx -g 'daemon of…"   3 minutes ago       Up 2 seconds        0.0.0.0:222->22/tcp, 0.0.0.0:8080->80/tcp   nginx
leoheng-MacBook-Pro:~ leo$ 

4. pause/unpause

Command Interpretation: The container is suspended or restored to suspend the container. The container cannot be used normally in the suspended state.

leoheng-MacBook-Pro:~ leo$ docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                       NAMES
feea481119cb        nginx:latest        "nginx -g 'daemon of…"   4 minutes ago       Up About a minute   0.0.0.0:222->22/tcp, 0.0.0.0:8080->80/tcp   nginx
leoheng-MacBook-Pro:~ leo$ docker pause feea481119cb
feea481119cb
leoheng-MacBook-Pro:~ leo$ docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                  PORTS                                       NAMES
feea481119cb        nginx:latest        "nginx -g 'daemon of…"   6 minutes ago       Up 2 minutes (Paused)   0.0.0.0:222->22/tcp, 0.0.0.0:8080->80/tcp   nginx
leoheng-MacBook-Pro:~ leo$ docker unpause feea481119cb
feea481119cb
leoheng-MacBook-Pro:~ leo$ docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                       NAMES
feea481119cb        nginx:latest        "nginx -g 'daemon of…"   6 minutes ago       Up 2 minutes        0.0.0.0:222->22/tcp, 0.0.0.0:8080->80/tcp   nginx
leoheng-MacBook-Pro:~ leo$ 

5. exec

Command Interpretation: Execute commands in running containers or enter containers

leoheng-MacBook-Pro:~ leo$ docker exec -it nginx  /bin/bash
root@feea481119cb:/# hostname 
feea481119cb
root@feea481119cb:/#

6. kill

Command Interpretation: Termination of a running container
Parameters:
- s: Send termination signal to container

leoheng-MacBook-Pro:~ leo$ docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                       NAMES
feea481119cb        nginx:latest        "nginx -g 'daemon of…"   14 minutes ago      Up 10 minutes       0.0.0.0:222->22/tcp, 0.0.0.0:8080->80/tcp   nginx
leoheng-MacBook-Pro:~ leo$ docker kill nginx
nginx
leoheng-MacBook-Pro:~ leo$ docker  ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
leoheng-MacBook-Pro:~ leo$

7. rm

Command Interpretation: Delete one or more containers
Parameters:
- f: Force removal of a running container by termination signal
- l: Remove network connections between containers, not containers themselves
- v: Delete volumes associated with containers

leoheng-MacBook-Pro:~ leo$ docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                       NAMES
feea481119cb        nginx:latest        "nginx -g 'daemon of…"   16 minutes ago      Up 41 seconds       0.0.0.0:222->22/tcp, 0.0.0.0:8080->80/tcp   nginx
leoheng-MacBook-Pro:~ leo$ docker rm nginx
Error response from daemon: You cannot remove a running container feea481119cb053e84bf3bda6f1b29beaddb3f91899f4d28775c4015f0dafa2f. Stop the container before attempting removal or force remove
leoheng-MacBook-Pro:~ leo$ docker stop  nginx
nginx
leoheng-MacBook-Pro:~ leo$ docker rm nginx
nginx
leoheng-MacBook-Pro:~ leo$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
leoheng-MacBook-Pro:~ leo$ 

II. Container Operation

1. ps

Command Interpretation: List Containers
Parameters:
- a: Display all containers, including those that are not running.
- f: Filter the displayed content according to conditions
format: Template for specifying return values
- l: Display recently created containers
- n: List the n containers recently created
- no-trunc: Uncut output
- q: Quiet mode, showing only container number
- s: Displays the total file size.

leoheng-MacBook-Pro:~ leo$ docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
leoheng-MacBook-Pro:~ leo$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                            PORTS               NAMES
feea481119cb        nginx:latest        "nginx -g 'daemon of…"   16 minutes ago      Exited (137) About a minute ago                       nginx
leoheng-MacBook-Pro:~ leo$

2. inspect

Command Interpretation: Getting Container/Mirror Metadata
Parameters:
- f: Template file specifying return value
- s: Display sad file size
--type: Returns json for the specified type

View the meta information of nginx:latest

leoheng-MacBook-Pro:~ leo$ docker inspect nginx:latest
[
    {
        "Id": "sha256:568c4670fa800978e08e4a51132b995a54f8d5ae83ca133ef5546d092b864acf",
        "RepoTags": [
            "nginx:latest"
        ],
        "RepoDigests": [
            "nginx@sha256:5d32f60db294b5deb55d078cd4feb410ad88e6fe77500c87d3970eca97f54dba"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2018-11-27T22:21:45.207738888Z",
        "Container": "1455cab9c97f6945336dd97d5dfca0429eacbb739fcd362cc528ed8a175fcc7b",
        "ContainerConfig": {
            "Hostname": "1455cab9c97f",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NGINX_VERSION=1.15.7-1~stretch",
                "NJS_VERSION=1.15.7.0.2.6-1~stretch"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"nginx\" \"-g\" \"daemon off;\"]"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:cf9409661039371fa3448619fb988625e4542108921c4c8f923c5bccc51601eb",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": [],
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
            },
            "StopSignal": "SIGTERM"
        },
        "DockerVersion": "17.06.2-ce",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NGINX_VERSION=1.15.7-1~stretch",
                "NJS_VERSION=1.15.7.0.2.6-1~stretch"
            ],
            "Cmd": [
                "nginx",
                "-g",
                "daemon off;"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:cf9409661039371fa3448619fb988625e4542108921c4c8f923c5bccc51601eb",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": [],
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
            },
            "StopSignal": "SIGTERM"
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 109116878,
        "VirtualSize": 109116878,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/b2a9c894aa016618fdae88f2cd152cf11f1f05461d927d4682efe60c4366f038/diff:/var/lib/docker/overlay2/a9bc2292493221b766a47272eb1d9d7c2b0049bda74a745dd82bc82443f5ec1f/diff",
                "MergedDir": "/var/lib/docker/overlay2/b9af4051377bdbc6e1435834a73ed8c23d5bb89bfef33eb199347ff315038f32/merged",
                "UpperDir": "/var/lib/docker/overlay2/b9af4051377bdbc6e1435834a73ed8c23d5bb89bfef33eb199347ff315038f32/diff",
                "WorkDir": "/var/lib/docker/overlay2/b9af4051377bdbc6e1435834a73ed8c23d5bb89bfef33eb199347ff315038f32/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:ef68f6734aa485edf13a8509fe60e4272428deaf63f446a441b79d47fc5d17d3",
                "sha256:ad5345cbb119f7c720123e3adf28b164143e4157ca6e46a629ca694e75f7825f",
                "sha256:ece4f9fdef598687f23d39643bacbf2c609201b087b93bbae81b931da72d2a64"
            ]
        },
        "Metadata": {
            "LastT
agTime": "0001-01-01T00:00:00Z"
        }
    }
]
leoheng-MacBook-Pro:~ leo$

ip method for obtaining containers

leoheng-MacBook-Pro:~ leo$ docker inspect -f {{.NetworkSettings.Networks.bridge.IPAddress}}  nginx
172.17.0.2

perhaps

leoheng-MacBook-Pro:~ leo$ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' nginx
172.17.0.2
leoheng-MacBook-Pro:~ leo$

3. top

Command Interpretation: View the process information running in the container and support the parameters of ps

leoheng-MacBook-Pro:~ leo$ docker top nginx
PID                 USER                TIME                COMMAND
3208                root                0:00                nginx: master process nginx -g daemon off;
3251                101                 0:00                nginx: worker process
leoheng-MacBook-Pro:~ leo$

View process information for all containers

leoheng-MacBook-Pro:~ leo$ for i in `docker ps |grep Up|awk '{print $1}'` ; do echo \ && docker top $i ; done

PID                 USER                TIME                COMMAND
3208                root                0:00                nginx: master process nginx -g daemon off;
3251                101                 0:00                nginx: worker process
leoheng-MacBook-Pro:~ leo$

4. logs

Command Interpretation: Get the container log
Parameters:
- f: Tracking log output
- since: Displays all logs for a start time
- t: Display timestamps
--tail: List only the latest N container logs

leoheng-MacBook-Pro:~ leo$ docker logs -f nginx 
172.17.0.1 - - [08/Dec/2018:03:22:35 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36" "-"
2018/12/08 03:22:36 [error] 24#24: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.1.3:8080", referrer: "http://192.168.1.3:8080/"
172.17.0.1 - - [08/Dec/2018:03:22:36 +0000] "GET /favicon.ico HTTP/1.1" 404 555 "http://192.168.1.3:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36" "-"
172.17.0.1 - - [08/Dec/2018:03:22:47 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36" "-"
172.17.0.1 - - [08/Dec/2018:03:23:48 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15" "-"
2018/12/08 03:23:48 [error] 24#24: *5 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.1.3:8080", referrer: "http://192.168.1.3:8080/"
172.17.0.1 - - [08/Dec/2018:03:23:48 +0000] "GET /favicon.ico HTTP/1.1" 404 153 "http://192.168.1.3:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15" "-"

View the latest 5 logs of container nginx from 2018/12/8

leoheng-MacBook-Pro:~ leo$ docker logs --since="2018-12-08" --tail=5 nginx
172.17.0.1 - - [08/Dec/2018:03:22:36 +0000] "GET /favicon.ico HTTP/1.1" 404 555 "http://192.168.1.3:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36" "-"
172.17.0.1 - - [08/Dec/2018:03:22:47 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36" "-"
172.17.0.1 - - [08/Dec/2018:03:23:48 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15" "-"
2018/12/08 03:23:48 [error] 24#24: *5 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.1.3:8080", referrer: "http://192.168.1.3:8080/"
172.17.0.1 - - [08/Dec/2018:03:23:48 +0000] "GET /favicon.ico HTTP/1.1" 404 153 "http://192.168.1.3:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15" "-"
leoheng-MacBook-Pro:~ leo$ 

5. events

Command Interpretation: Getting Real-time Events from the Server
Parameters:
- f: filter events according to conditions;
since: Displays all events from the specified timestamp;
Until: the running time is displayed until the specified time;

Get all events for 2018/12/8

leoheng-MacBook-Pro:~ leo$ docker events --since="2018-12-08" 
2018-12-08T09:46:57.832351102+08:00 image pull nginx:latest (maintainer=NGINX Docker Maintainers <docker-maint@nginx.com>, name=nginx)
2018-12-08T09:46:57.938764857+08:00 container create 3a9e561b7629c6880c776a9331dcc9d052685f08c98f58c940e1a164c1f8d77c (image=nginx:latest, maintainer=NGINX Docker Maintainers <docker-maint@nginx.com>, name=mynginx)
2018-12-08T10:23:52.553078826+08:00 container create feea481119cb053e84bf3bda6f1b29beaddb3f91899f4d28775c4015f0dafa2f (image=nginx:latest, maintainer=NGINX Docker Maintainers <docker-maint@nginx.com>, name=nginx)
2018-12-08T10:23:52.678445332+08:00 network connect 2651d136cf62ba9dc0ebe674eca0c1d9f73cf4230e345aec01be0ddd797715bb (container=feea481119cb053e84bf3bda6f1b29beaddb3f91899f4d28775c4015f0dafa2f, name=bridge, type=bridge)
2018-12-08T10:23:53.133906581+08:00 container start feea481119cb053e84bf3bda6f1b29beaddb3f91899f4d28775c4015f0dafa2f (image=nginx:latest, maintainer=NGINX Docker Maintainers <docker-maint@nginx.com>, name=nginx)
2018-12-08T10:25:07.949445750+08:00 container destroy 3a9e561b7629c6880c776a9331dcc9d052685f08c98f58c940e1a164c1f8d77c (image=nginx:latest, maintainer=NGINX Docker Maintainers <docker-maint@nginx.com>, name=mynginx)

If the specified time is in seconds, the time needs to be converted to a timestamp. If the time is a date, it can be used directly, such as - since="2016-07-01".

6. wait

Command description: Blocking runs until the container stops, and then prints out its exit code

leoheng-MacBook-Pro:~ leo$ docker wait nginx

7. attach

Command Interpretation: Connect to a running container
sig-proxy: Prevent CTRL+D or CRTL+C from exiting containers

leoheng-MacBook-Pro:~ leo$ docker attach --sig-proxy=false nginx
172.17.0.1 - - [08/Dec/2018:03:37:47 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15" "-"

8. port

Command Interpretation: List the port mapping of the specified container, or find the port that will PRIVATE_PORT NAT to the public.

leoheng-MacBook-Pro:~ leo$ docker port nginx 
22/tcp -> 0.0.0.0:222
80/tcp -> 0.0.0.0:8080
leoheng-MacBook-Pro:~ leo$

9. export

Command Interpretation: Export the file system as a tar archive file to STDOUT. Save the current mirror state.

leoheng-MacBook-Pro:~ leo$ docker export -o nginx-leo.tar nginx
leoheng-MacBook-Pro:~ leo$ ls nginx-leo.tar 
nginx-leo.tar
leoheng-MacBook-Pro:~ leo$ 

3. Container rootfs command

1. commit

Command Interpretation: Create a new image from the container and submit it to the mirror library.
Parameters:
- a: Submitted mirror author;
- c: Use Dockerfile instructions to create images;
- m: Description at the time of submission;
- p: When commit, suspend the container.

leoheng-MacBook-Pro:~ leo$ docker commit -a "leo"  -m "leo commit nginx test"  nginx  leo:v1 
sha256:6ec4ef7718a8b311f261e8eb12f2b55a42f631e75ad7cd7a5c105620c6abd7ce
leoheng-MacBook-Pro:~ leo$ docker images  leo:v1
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
leo                 v1                  6ec4ef7718a8        10 seconds ago      109MB
leoheng-MacBook-Pro:~ leo$

2. cp

Command Description: Used for data copy between container and host
Description of parameters:
- L: Keep links in source targets

leoheng-MacBook-Pro:~ leo$ echo "nginxtest"  >> test
leoheng-MacBook-Pro:~ leo$ docker cp test  nginx:/
leoheng-MacBook-Pro:~ leo$ docker exec -it nginx /bin/bash
root@96ddce20c551:/# cat test
nginxtest
root@96ddce20c551:/#

3. diff

Command description: Check file structure changes in containers

leoheng-MacBook-Pro:~ leo$ docker diff nginx
C /run
A /run/nginx.pid
C /var
C /var/cache
C /var/cache/nginx
A /var/cache/nginx/client_temp
A /var/cache/nginx/fastcgi_temp
A /var/cache/nginx/proxy_temp
A /var/cache/nginx/scgi_temp
A /var/cache/nginx/uwsgi_temp
C /root
A /root/.bash_history
A /test
leoheng-MacBook-Pro:~ leo$

IV. Mirror Warehouse

1. login/logout

Command Interpretation: Log in or log out of docker mirror warehouse
Parameters:
- u: Login username
- p: Login password

Because I downloaded the docker client and typed it directly

leoheng-MacBook-Pro:~ leo$ docker login –u leo –p *******
Authenticating with existing credentials...
Login Succeeded
leoheng-MacBook-Pro:~ leo$ 

2. pull

Command Interpretation: Get the mirror from Mirror Kura to update the specified image alive
Parameters:
- a: pull all tagged images
- disable-content-trust: Ignore mirror checking and open by default

leoheng-MacBook-Pro:~ leo$ docker pull nginx

3. push

Command Interpretation: To upload the local image to the mirror warehouse, you must first log in to the mirror warehouse.
Parameters:
- disable-content-trust: Ignore mirror checking and open by default

leoheng-MacBook-Pro:~ leo$ docker push leo:v1
The push refers to repository [docker.io/library/leo]
fae8ad5437e1: Preparing 
ece4f9fdef59: Preparing 
ad5345cbb119: Preparing 
ef68f6734aa4: Preparing 
denied: requested access to the resource is denied
leoheng-MacBook-Pro:~ leo$ 

4. search

Command Interpretation: Find Mirror from docker hub
Parameters:
- Automated: List only the mirrors of the automated build type;
no-trunc: Displays a complete mirror description;
- s: Lists images with a collection number not less than the specified value.

leoheng-MacBook-Pro:~ leo$ docker search nginx
NAME                                                   DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
nginx                                                  Official build of Nginx.                        10502               [OK]                
jwilder/nginx-proxy                                    Automated Nginx reverse proxy for docker con…   1483                                    [OK]
richarvey/nginx-php-fpm                                Container running Nginx + PHP-FPM capable of…   660                                     [OK]
jrcs/letsencrypt-nginx-proxy-companion                 LetsEncrypt container to use with nginx as p…   450                                     [OK]
kong                                                   Open-source Microservice & API Management la…   257                 [OK]                
webdevops/php-nginx                                    Nginx with PHP-FPM                              118                                     [OK]

V. Local Mirror Management

1. images

Command Interpretation: List Local Mirrors
parameter
- a: List all local mirrors (including the intermediate image layer, by default, filter out the intermediate image layer);
digests: Display summary information of the mirror image;
- f: Display a mirror that meets the criteria;
Form: Template file specifying the return value;
no-trunc: Displays complete mirror information;
- q: Only the mirror ID is displayed.

leoheng-MacBook-Pro:~ leo$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
leo                 v1                  6ec4ef7718a8        5 hours ago         109MB
nginx               latest              568c4670fa80        10 days ago         109MB
leoheng-MacBook-Pro:~ leo$ 

2. tag

Command description: Mark the local image and place it in a warehouse

leoheng-MacBook-Pro:~ leo$ docker tag 6ec4ef7718a8 leoheng/leo:v1
leoheng-MacBook-Pro:~ leo$ docker images leoheng/leo:v1
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
leoheng/leo         v1                  6ec4ef7718a8        5 hours ago         109MB
leoheng-MacBook-Pro:~ leo$

3. history

Command Interpretation: View the Creation History of the Specified Image
Parameters:
- H: Print mirror size and date in readable format, default to true;
- no-trunc: Displays complete submission records;
- q: List only the submission record ID.

leoheng-MacBook-Pro:~ leo$ docker history leoheng/leo:v1
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
6ec4ef7718a8        5 hours ago         nginx -g daemon off;                            108B                leo commit nginx test
568c4670fa80        10 days ago         /bin/sh -c #(nop)  CMD ["nginx" "-g" "daemon…   0B                  
<missing>           10 days ago         /bin/sh -c #(nop)  STOPSIGNAL [SIGTERM]         0B                  
<missing>           10 days ago         /bin/sh -c #(nop)  EXPOSE 80/tcp                0B                  
<missing>           10 days ago         /bin/sh -c ln -sf /dev/stdout /var/log/nginx…   22B                 
<missing>           10 days ago         /bin/sh -c set -x  && apt-get update  && apt…   53.8MB              
<missing>           10 days ago         /bin/sh -c #(nop)  ENV NJS_VERSION=1.15.7.0.…   0B                  
<missing>           10 days ago         /bin/sh -c #(nop)  ENV NGINX_VERSION=1.15.7-…   0B                  
<missing>           3 weeks ago         /bin/sh -c #(nop)  LABEL maintainer=NGINX Do…   0B                  
<missing>           3 weeks ago         /bin/sh -c #(nop)  CMD ["bash"]                 0B                  
<missing>           3 weeks ago         /bin/sh -c #(nop) ADD file:dab9baf938799c515…   55.3MB              
leoheng-MacBook-Pro:~ leo$ 

4. build

Command Interpretation: Used to create mirrors for Dockerfile
parameter
build-arg=[]: Sets the variables at the time of image creation;
- cpu-shares: Setting the weight of CPU usage;
- cpu-period: Limit the CPU CFS cycle;
- cpu-quota: Limit CPU CFS quotas;
- cpuset-cpus: the specified CPU id;
- cpuset-mems: Specifies the memory id to be used;
- disable-content-trust: Ignore validation and open by default;
- f: Specify the Dockerfile path to use;
force-rm: Delete the intermediate container in the process of setting up the image;
- isolation: using container isolation technology;
- label=[]: Setting metadata for mirroring;
- m: Set the maximum memory;
memory-swap: Set the maximum value of Swap to memory + swap, and "-1" means unlimited swap.
no-cache: The process of creating an image does not use caching;
- pull: Try to update the new version of the mirror;
- quiet, -q: quiet mode, only output mirror ID after success;
- rm: Delete the intermediate container after setting the mirror successfully.
- shm-size: Set the size of / dev/shm with a default value of 64M;
-- ulimit: Ulimit configuration.
- tag, -t: Mirror name and label, usually in name:tag or name format; multiple labels can be set for a single image in a single build.
Network: default. Setting the network mode of RUN instructions during construction

Create an image using the Dockerfile of the current directory labeled runoob/ubuntu:v1.

docker build -t runoob/ubuntu:v1 .

Create an image using the Dockerfile of the URL github.com/creack/docker-firefox.

docker build github.com/creack/docker-firefox

You can also use the location of the - f Dockerfile file:

docker build -f /path/to/a/Dockerfile .

Before the Docker daemon executes the instructions in the Dockerfile, it first checks the grammar of the Dockerfile and returns if there is a grammar error:

$ docker build -t test/myapp .
Sending build context to Docker daemon 2.048 kB
Error response from daemon: Unknown instruction: RUNCMD

5. save

Command Interpretation: Save the specified image as a tar Archive

leoheng-MacBook-Pro:~ leo$ docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                       NAMES
96ddce20c551        nginx:latest        "nginx -g 'daemon of…"   6 hours ago         Up 5 hours          0.0.0.0:222->22/tcp, 0.0.0.0:8080->80/tcp   nginx
leoheng-MacBook-Pro:~ leo$ docker save -o nginx_leo_v1.tar  nginx
leoheng-MacBook-Pro:~ leo$ ls nginx_leo_v1.tar 
nginx_leo_v1.tar
leoheng-MacBook-Pro:~ leo$

6. import

Command Interpretation: Creating Mirrors from Archives
parameter
- c: Use docker instructions to create images;
- m: Description at the time of submission;

leoheng-MacBook-Pro:~ leo$ docker import nginx_leo_v1.tar  leoheng/leo:v1
sha256:7afc0a247e015d0984f67a8b694c7c8e8363138c7ca6e4c3c69b583c2322774e
leoheng-MacBook-Pro:~ leo$

7. rmi

Command Interpretation: Delete one or more local mirrors
Parameters:
- f: Forced deletion;
no-prune: The process image of the image is not removed by default.

leoheng-MacBook-Pro:~ leo$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
leoheng/leo         v1                  7afc0a247e01        About a minute ago   113MB
nginx               latest              568c4670fa80        10 days ago          109MB
leoheng-MacBook-Pro:~ leo$ docker rmi 7afc0a247e01
Untagged: leoheng/leo:v1
Deleted: sha256:7afc0a247e015d0984f67a8b694c7c8e8363138c7ca6e4c3c69b583c2322774e
Deleted: sha256:c0b54e54ff0bfd2330f0a541c02bf5706674cc3d2b0c7899457a5d543acaacff
leoheng-MacBook-Pro:~ leo$ 

6. View docker version information

1. info
Command Interpretation: Display docker system information, including mirrors and number of containers

leoheng-MacBook-Pro:~ leo$ docker info
Containers: 1
 Running: 1
 Paused: 0
 Stopped: 0
Images: 2
Server Version: 18.09.0
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.125-linuxkit
Operating System: Docker for Mac
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.952GiB
Name: linuxkit-025000000001
ID: 4CPI:PVLC:WBJL:QQPX:JP2X:B7RP:MGYE:SA7Y:ULC5:YOSL:RAYE:EMFD

2. version
Command Interpretation: Display docker version information
Parameters:
- f: A template file that specifies the return value.

leoheng-MacBook-Pro:~ leo$ docker version 
Client: Docker Engine - Community
 Version:           18.09.0
 API version:       1.39
 Go version:        go1.10.4
 Git commit:        4d60db4
 Built:             Wed Nov  7 00:47:43 2018
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.0
  API version:      1.39 (minimum version 1.12)+
  Go version:       go1.10.4
  Git commit:       4d60db4
  Built:            Wed Nov  7 00:55:00 2018
  OS/Arch:          linux/amd64
  Experimental:     false
leoheng-MacBook-Pro:~ leo$ 

Posted by magnetica on Wed, 20 Mar 2019 10:33:28 -0700