Lists the mirror list (docker images)
[root@master docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest fce289e99eb9 7 months ago 1.84kB [root@master docker]#
Various indicators Item Description ::
the REPOSITORY: representation mirrored warehouse source
TAG: image tag
IMAGE ID: Mirror ID
CREATED: Mirror Created
SIZE: image size
Boot image (docker run)
Docker allows you to run within the container application to run an application in the containers docker run command.
grammar
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Parameter Description:
-a stdin: Specifies the standard input and output content types, optionally STDIN / STDOUT / STDERR three;
-d: background container, and returns the container ID;
-i: Run vessel in interactive mode, typically used in conjunction with -t;
- P: (the inside of the container used in the network to the host port mapping we use) random port mapping, the container inner mapped to the host port random high port
-p: Specifies port mapping format: a host (host) port: the port of the container
-t: reassigned as a pseudo input terminal container, generally used in conjunction with -i;
--name = "Nginx-LB": a name container;
- DNS 8.8.8.8: Specifies the DNS server to use the container, the default host and consistent;
- DNS-Search the example.com: DNS search domain specified container, and consistent with the default host;
-H "Mars": hostname specified container;
-e username = "Ritchie": set environment variables;
--env -file = []: to read the file from the specified environment variable;
--cpuset = "0-2" or --cpuset = "0,1,2": bind to a designated container CPU operation;
-m: containers provided maximum memory;
- net = "Bridge": network connection type of the container, branched, bridge / host / none / container: four types;
--link = []: add a link to another vessel;
--expose = []: opening a port or a group of ports;
--volume, -v:
Examples
Use docker mirror nginx: mode starts after a latest table container, and the container name mynginx.
docker run --name mynginx -d nginx:latest
Mirroring nginx: mode starts after a latest table container port 80 and container port random mapped to the host.
docker run -P -d nginx:latest
Mirroring nginx: latest, background mode starts a container, the container port 80 is mapped to the directory port 80, host host / data mapped to the container / data.
docker run -p 80:80 -v /data:/data -d nginx:latest
Binding container port 8080, and mapped to the port 80 of the local host 127.0.0.1.
docker run -p 127.0.0.1:80:8080/tcp ubuntu bash
Mirroring nginx: latest start a container in interactive mode, execute / bin / bash command within the container.
root@master docker]# docker run -it nginx:latest /bin/bash
root@b8573233d675:/#
Mirroring centos start a container in interactive mode, execute / bin / bash command within the container.
root@master docker]# docker run --name mydocker -t -i centos /bin/bash Unable to find image 'centos:latest' locally latest: Pulling from library/centos d8d02d457314: Pull complete Digest: sha256:307835c385f656ec2e2fec602cf093224173c51119bbebd602c53c3653a3d6eb Status: Downloaded newer image for centos:latest [root@1d8a5ab31830 /]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 11820 1896 pts/0 Ss 15:00 0:00 /bin/bash root 15 0.0 0.0 51740 1732 pts/0 R+ 15:01 0:00 ps aux [root@1d8a5ab31830 /]# [root@1d8a5ab31830 /]# exit exit [root@master docker]#
# Create a file directory to mount the container, do oracle position data backup data storage, backup to ensure data is not lost. mkdir / usr / local / data_temp the chmod 777 / usr / local / data_temp Docker RUN -d -p --name oracle12c 1521 : 1521 -v / usr / local / data_temp: / Home / Oracle / data_temp sath89 / oracle12c
NOTE: oracle12c name, -p is a port mapping, -v host is mapping the / usr / local / data_temp directory to / home in the container / oracle / inner data_temp.
Listed container list (docker ps)
Syntax
Docker PS [the OPTIONS]
the OPTIONS DESCRIPTION:
-a: show all containers, including not running.
-f: filtering content displayed according to the conditions.
--format: Specifies the return value of the template file.
-l: display container recently created.
-n: list n containers recently created.
--no-trunc: do not cut output.
-q: Silent mode, only the container number.
-s: Displays the total file size.
root@master docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
32098924b2e0 hello-world "/hello" 6 minutes ago Exited (0) 6 minutes ago hopeful_northcutt
b07906c995f3 hello-world "/hello" 7 minutes ago Exited (0) 7 minutes ago keen_goldstine
[root@master docker]# docker ps -a -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
32098924b2e0 hello-world "/hello" 8 minutes ago Exited (0) 8 minutes ago hopeful_northcutt
The last time the query was created container
[root@master docker]# docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/ [root@master docker]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 99d7fbb94565 hello-world "/hello" 3 seconds ago Exited (0) 3 seconds ago gracious_panini 1d8a5ab31830 centos "/bin/bash" 34 minutes ago Exited (137) 4 minutes ago mydocker [root@master docker]# docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 99d7fbb94565 hello-world "/hello" 21 seconds ago Exited (0) 21 seconds ago gracious_panini [root@master docker]#
Into the container method
A, attach (not recommended)
Note: This method exit to exit the container after the process is over, the container is closed. Not recommended for use
[root@master docker]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1d8a5ab31830 centos "/bin/bash" 4 minutes ago Exited (0) 2 minutes ago mydocker 32098924b2e0 hello-world "/hello" 16 minutes ago Exited (0) 16 minutes ago hopeful_northcutt b07906c995f3 hello-world "/hello" 17 minutes ago Exited (0) 17 minutes ago keen_goldstine [root@master docker]# docker start 1d8a5ab31830 #再次将容器启动 1d8a5ab31830 [root@master docker]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1d8a5ab31830 centos "/bin/bash" 5 minutes ago Up 6 seconds mydocker 32098924b2e0 hello-world "/hello" 16 minutes ago Exited (0) 16 minutes ago hopeful_northcutt b07906c995f3 hello-world "/hello" 18 minutes ago Exited (0) 18 minutes ago keen_goldstine [root@master docker]# docker attach 1d8a5ab31830 [root@1d8a5ab31830 /]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin [root@1d8a5ab31830 /]# exit exit [root@master docker]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1d8a5ab31830 centos "/bin/bash" 8 minutes ago Exited (0) 3 seconds ago mydocker 32098924b2e0 hello-world "/hello" 19 minutes ago Exited (0) 19 minutes ago hopeful_northcutt b07906c995f3 hello-world "/hello" 20 minutes ago Exited (0) 20 minutes ago keen_goldstine [root@master docker]#
attach summary: a container specifies a process, the container quit. His generation cycle is over, it withdrew.
Two, exec
Note: This method is when the exit to exit the container, not the end of the process, the container is not closed.
docker exec -it 1d8a5ab31830 / bin / bash # 1d8a5ab31830 wherein the container ID number
docker exec: Run run vessel
OPTIONS DESCRIPTION:
-d: Split mode: the background
-i: STDIN maintained even without additional open
-t : assign a pseudo-terminal
[root@master docker]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1d8a5ab31830 centos "/bin/bash" 8 minutes ago Exited (0) 3 seconds ago mydocker 32098924b2e0 hello-world "/hello" 19 minutes ago Exited (0) 19 minutes ago hopeful_northcutt b07906c995f3 hello-world "/hello" 20 minutes ago Exited (0) 20 minutes ago keen_goldstine [root@master docker]# docker exec -it 1d8a5ab31830 /bin/bash Error response from daemon: Container 1d8a5ab31830dc16e3129a6e123a5c16bc10989aeced01a3be62d236ee76cb0d is not running [root@master docker]# docker start 1d8a5ab31830 1d8a5ab31830 [root@master docker]# docker exec -it 1d8a5ab31830 /bin/bash [root@1d8a5ab31830 /]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin [root@1d8a5ab31830 /]# exit exit [root@master docker]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1d8a5ab31830 centos "/bin/bash" 10 minutes ago Up 23 seconds mydocker 32098924b2e0 hello-world "/hello" 21 minutes ago Exited (0) 21 minutes ago hopeful_northcutt b07906c995f3 hello-world "/hello" 23 minutes ago Exited (0) 23 minutes ago keen_goldstine [root@master docker]#
Three, nsenter (recommended to use this command into the container)
Note: After exiting the container, the container can make another run in the background. Recommended to use this command into the container.
[root@master docker]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1d8a5ab31830 centos "/bin/bash" 10 minutes ago Up 23 seconds mydocker 32098924b2e0 hello-world "/hello" 21 minutes ago Exited (0) 21 minutes ago hopeful_northcutt b07906c995f3 hello-world "/hello" 23 minutes ago Exited (0) 23 minutes ago keen_goldstine [root@master docker]# docker stop 1d8a5ab31830 1d8a5ab31830 [root@master docker]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1d8a5ab31830 centos "/bin/bash" 13 minutes ago Exited (137) 4 seconds ago mydocker 32098924b2e0 hello-world "/hello" 24 minutes ago Exited (0) 24 minutes ago hopeful_northcutt b07906c995f3 hello-world "/hello" 26 minutes ago Exited (0) 26 minutes ago keen_goldstine [root@master docker]# docker start 1d8a5ab31830 #要先启动容器,才能进入容器里边 1d8a5ab31830 [root@master docker]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1d8a5ab31830 centos "/bin/bash" 13 is minutes ago Member Up . 5 seconds The mydocker [the root @ Master Docker] # Docker Inspect --format " {} {} .State.Pid " 1d8a5ab31830 process vessel # View ID 2841 [the root @ Master Docker] # nsenter -t 2841 -u -i - the n-# into the container [root @ 1d8a5ab31830 Docker] # [root @ 1d8a5ab31830 Docker] # # exit to exit the container, still in the process Zimbabwe Logout [root @ Master Docker] # Docker PS cONTAINER PORTS the STATUS ID the IMAGE CREATED the COMMAND NAMES 1d8a5ab31830 CentOS " / bin / bash" 15 minutes ago Up About a minute mydocker [root@master docker]#
You can write a script to facilitate the entry of the container:
[root@master docker]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1d8a5ab31830 centos "/bin/bash" 21 minutes ago Up 7 minutes mydocker [root@master docker]# echo '' > shelldocker.sh [root@master docker]# [root@master docker]# vi shelldocker.sh #!/bin/bash PID=$(docker inspect --format "{{.State.Pid}}" $1) nsenter -t $PID -u -i -n ~ "shelldocker.sh" 3L, 88C written [root@master docker]# [root@master docker]# ls shelldocker.sh [root@master docker]# chmod +x shelldocker.sh [root@master docker]# [root@master docker]# ./shelldocker.sh 1d8a5ab31830 [root@1d8a5ab31830 docker]# exit logout [root@master docker]#
Find Mirror (pull nginx Mirror)
Use docker search command to search for a mirror site from Docker Hub
docker search nginx (Find Mirror)
[root@master docker]# docker search nginx NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Official build of Nginx. 11852 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1641 [OK] richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 735 [OK] linuxserver/nginx An Nginx container, brought to you by LinuxS… 73 bitnami/nginx Bitnami nginx Docker Image 70 [OK] tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 51 [OK] jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 23 nginxdemos/hello NGINX webserver that serves a simple page co… 23 [OK] nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 20 jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 20 [OK] schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 17 [OK] crunchgeek/nginx-pagespeed Nginx with PageSpeed + GEO IP + VTS + more_s… 13 blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 12 [OK] centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 11 centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 10 nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 9 sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats a… 5 [OK] nginx/nginx-prometheus-exporter NGINX Prometheus Exporter 5 1science/nginx Nginx Docker images that include Consul Temp… 5 [OK] mailu/nginx Mailu nginx frontend 3 [OK] pebbletech/nginx-proxy nginx-proxy sets up a container running ngin… 2 [OK] travix/nginx NGinx reverse proxy 2 [OK] centos/nginx-110-centos7 Platform for running nginx 1.10 or building … 0 ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 0 [OK] wodby/nginx Generic nginx 0 [OK]
docker pull nginx (mirrored pull)
[root@master docker]# docker pull nginx Using default tag: latest latest: Pulling from library/nginx 1ab2bdfe9778: Pull complete a17e64cfe253: Pull complete e1288088c7a8: Pull complete Digest: sha256:53ddb41e46de3d63376579acf46f9a41a8d7de33645db47a486de9769201fec9 Status: Downloaded newer image for nginx:latest [root@master docker]#
The standard output of the internal container (docker logs)
docker logs [ID or name] can view the interior of the container standard output
$ docker logs 353e6c82b2fc
$ docker logs -f 353e6c82b2fc
-f: Let dokcer logs the same as using the tail -f to standard output inside the container.
docker logs [ID or name]
[root@master docker]# docker logs 1d8a5ab31830 [root@1d8a5ab31830 /]# ps aux bash: 平ps: command not found [root@1d8a5ab31830 /]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 11820 1896 pts/0 Ss 15:00 0:00 /bin/bash root 15 0.0 0.0 51740 1732 pts/0 R+ 15:01 0:00 ps aux [root@1d8a5ab31830 /]# [root@1d8a5ab31830 /]# exit exit [root@1d8a5ab31830 /]# echo PATH PATH [root@1d8a5ab31830 /]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin [root@1d8a5ab31830 /]# exit exit [root@1d8a5ab31830 /]# [root@master docker]#
docker logs -f [ID or name]
root@master docker]# docker logs -f 1d8a5ab31830 [root@1d8a5ab31830 /]# ps aux bash: 平ps: command not found [root@1d8a5ab31830 /]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 11820 1896 pts/0 Ss 15:00 0:00 /bin/bash root 15 0.0 0.0 51740 1732 pts/0 R+ 15:01 0:00 ps aux [root@1d8a5ab31830 /]# [root@1d8a5ab31830 /]# exit exit [root@1d8a5ab31830 /]# echo PATH PATH [root@1d8a5ab31830 /]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin [root@1d8a5ab31830 /]# exit exit [root@1d8a5ab31830 /]#
Stop the application container (docker stop)
$ Docker stop [cid | names] (cid and containers can use the name)
[root@master docker]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1d8a5ab31830 centos "/bin/bash" 29 minutes ago Up 15 minutes mydocker [root@master docker]# docker stop mydocker mydocker [root@master docker]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@master docker]#
Remove the application container (docker rm)
$ Docker rm [CID | NAMES] and containers can use the cid name)
$ docker rm -f CID|NAMES
[root@master docker]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1d8a5ab31830 centos "/bin/bash" 31 minutes ago Exited (137) About a minute ago mydocker 32098924b2e0 hello-world "/hello" 42 minutes ago Exited (0) 42 minutes ago hopeful_northcutt b07906c995f3 hello-world "/hello" 44 minutes ago Exited (0) 44 minutes ago keen_goldstine [root@master docker]# docker rm hopeful_northcutt hopeful_northcutt [root@master docker]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1d8a5ab31830 centos "/bin/bash" 31 minutes ago Exited (137) About a minute ago mydocker b07906c995f3 hello-world "/hello" 44 minutes ago Exited (0) 44 minutes ago keen_goldstine [root@master docker]# docker rm b07906c995f3 b07906c995f3 [root@master docker]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1d8a5ab31830 centos "/bin/bash" 32 minutes ago Exited (137) 2 minutes ago mydocker [root@master docker]#
Create a new image (docker commit) from the container
Syntax
Docker commit [the OPTIONS] CONTAINER [the REPOSITORY [: TAG]]
the OPTIONS Description:
-a: Mirror of submission;
-c: Use Dockerfile command to create a mirror;
-m: Caption the time of filing;
-p: When commit the vessel was suspended.
Examples
The container a404c6c174a2 saved as a new image, and add author information and description information.
[root @ Master Docker] # Docker the commit -a " runoob.com (Mirror of submission) " -m " My the Apache (submit a caption) " a404c6c174a2 mymysql: v1 sha256: 37af1236adef1544e8886be23010b66577647a40bc02c0885a6600b33ee28057 [root @ Master Docker] # Docker mymysql Images: V1 the REPOSITORY the TAG ID CREATED the IMAGE SIZE mymysql V1 37af1236adef 15 seconds The ago Member 329 MB
Docker delete a container with a mirror (not recommended, use pay attention)
Stop all of the container, so that it can delete images in which:
docker stop $(docker ps -a -q) docker kill $(docker ps -a -q)
If you want to remove all the container, then add a command:
docker rm $(docker ps -a -q)
Delete images, specified by id image of who deleted
docker rmi <image id>
You want to delete untagged images, that is, those with id of image, then you can use
docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
To delete all of the image of words
docker rmi $(docker images -q)
Then forced to delete all image
docker rmi -f $(docker images -q)
Reference: "2, CentOS7 Docker basic installation and use, link: https: //blog.csdn.net/weixin_41515615/article/details/81349688"