(Shang Zhouyang) docker's notes

1. Preparation

docker :Docker
cat /etc/redhat-release  see sentOS edition
uname -r		View kernel version

2.docker architecture

Three elements: (warehouse, image and container)

docker host(Host): Installed Docker Programmed machine( Docker Directly installed on the operating system);

docker client(Client): connect docker Operate the host;

docker Warehouse(Registry): A place for centralized storage of images;

docker image(Images): A mirror is a read-only template used to create Docker Container, a mirror can create multiple containers

docker container(Container): Containers are running instances created with images, docker An application or group of applications that run independently with a container

Installing docker for CentOS7

 Install as above

Reference documents:

Alibaba cloud image acceleration:
https://h76augfk.mirror.aliyuncs.com acceleration address

to configure:

vim /etc/docker/daemon.json

Add the following content and apply for the specific address yourself
 "registry-mirrors": ["https://h76augfk.mirror.aliyuncs.com"]

Restart service
systemctl daemon-reload
systemctl restart docker


start-up  systemctl start docker
 Set startup and self startup  systemctl enable docker
 stop it		systemctl stop docker
 View run process commands		ps -ef | grep docker

Help command

docker version
docker info
docker help List of all instructions

Mirror command

1.docker images

  • List the images on the local host (repository warehouse tag image id image id create creation time size)
  • You can define different images through repository: tag
    • -a: List all local mirrors

    • -q: Only the mirror ID is displayed

    • – digests: summary information

    • – no TRUNC: (no interception) displays the complete image information

2.docker search xxx

  • From hub docker. Pull xxx starts to like official on. Com
  • -s 30 lists images with starts no less than 30
  • – no TRUNC does not intercept
  • – automated lists only images of the automated type
  • Latest latest deamon: virtual optical drive

3.docker pull Download Image

4.docker rmi (remove image)

Delete a mirror

  • -f force deletion
  • Remove multiple spaces between
  • Delete all $(docker imsges -qa)

Container command:

1. Create a new container and start it

docker run
-it launch interactive container
For example: docker run -it --name=mycentos01 centos

--name= xx  :Rename container to xx
-d:Background run container
-i:Interactive run container   interactive interactive  **
-t:Reassign a pseudo input terminal to the container 		teletype Teletypewriter**
-P:Random port mapping
-p:Specify port mapping
	hostPort:containerPort  **

2. List all currently running containers

docker ps

-a: all All containers (now)+(run)
-l: Show previous container    Recently created container
-n X: Displays the newly created X Containers
-q:In silent mode, only the container number is displayed  **
--no-trunc: Do not truncate output

Exit container

Exit: close the container and exit
ctrl+P+Q: the container does not stop, exits, or closes

Start container

docker start xxx

Restart container

docker restart xxx

Stop container

docker stop xxx

Force stop container

docker kill xxx

Delete stopped container

docker rm xxx
docker rm -f xxx
docker rm -f $(docker ps -a -q)
docker ps -aq | xargs docker rm


Start daemon container

docker run -d xxx

  • When the docker container runs in the background, there must be a foreground process. If the running command is not a suspended command (such as top and tail), it will exit automatically
  • Best solution: run the program you want to run as a previous process

View container log

docker logs -f -t --tail xxx

  • -t add timestamp
  • -f follow the latest log print to continuously view the docker log
  • – tail number: displays the last number of tails

View the processes running in the container

docker top xxxx

View container interior details

docker inspect xxxx

Enter the running container and interact with it on the command line

  • docker exec -it container ID ls -l /tmp: get the result directly without entering the docker container
  • docker exec -it container ID /bin/bash: entering the docker container is the same as the attach
    • exec: you can re-enter or get data without entering.. (you can open a new terminal and start a new process)
  • docker attach container ID: re entering
    • attach: re-enter

Copy files from the container to the host

docker cp XXXX : In container path destination host path
docker cp XXXX : /tmp/yum.log   /root  		take/tmp/yum.log Copy files to root Directory

Docker help common commands

attach    Attach to a running container         # The attach connection under the current shell specifies the running image

build     Build an image from a Dockerfile        # Customized image through Dockerfile

commit    Create a new image from a container changes  # Commit the current container as a new image

cp        Copy files/folders from the containers filesystem to the host path  #Copy the specified file or directory from the container to the host

create    Create a new container                        # Create a new container, the same as run, but do not start the container

diff      Inspect changes on a container's filesystem   # View docker container changes

events    Get real time events from the server          # Get container real-time events from docker service

exec      Run a command in an existing container        # Run the command on an existing container

export    Stream the contents of a container as a tar archive   # Export the content stream of the container as a tar archive [corresponding to import]

history   Show the history of an image                  # Show a mirror formation history

images    List images                                   # Lists the current image of the system

import    Create a new filesystem image from the contents of a tarball # Create a new file system image from the contents of the tar package [corresponding to export]

info      Display system-wide information               # Display system related information

inspect   Return low-level information on a container   # View container details

kill      Kill a running container                      # kill specifies the docker container

load      Load an image from a tar archive              # Load an image from a tar package [corresponding to save]

login     Register or Login to the docker registry server    # Register or log in to a docker source server

logout    Log out from a Docker registry server          # Exit from the current Docker registry

logs      Fetch the logs of a container                 # Output current container log information

port      Lookup the public-facing port which is NAT-ed to PRIVATE_PORT    # View the internal source port of the container corresponding to the mapped port

pause     Pause all processes within a container        # Pause container

ps        List containers                               # List containers

pull      Pull an image or a repository from the docker registry server   # Pull the specified image or library image from the docker image source server

push      Push an image or a repository to the docker registry server    # Push the specified image or library image to the docker source server

restart   Restart a running container                   # Restart the running container

rm        Remove one or more containers                 # Remove one or more containers

rmi       Remove one or more images             # Remove one or more images [no container can be deleted without using the image, otherwise relevant containers need to be deleted before continuing or -f forced deletion]

run       Run a command in a new container              # Create a new container and run a command

save      Save an image to a tar archive                # Save an image as a tar package [corresponding to load]

search    Search for an image on the Docker Hub         # Search for images in docker hub

start     Start a stopped containers                    # Start container

stop      Stop a running containers                     # Stop container

tag       Tag an image into a repository                # Label images in source

top       Lookup the running processes of a container   # View the process information running in the container

unpause   Unpause a paused container                    # Unsuspend container

version   Show the docker version information           # View docker version number

wait      Block until a container stops, then print its exit code   # Intercepts the exit status value when the container stops

Keywords: Java Linux CentOS Docker

Added by NNTB on Sat, 15 Jan 2022 03:27:33 +0200