docker maintenance operations

1. Pause and resume all processes in the container (pause/unpause)

  • docker pause: Pause all processes in the container.
  • docker unpause: Resume all processes in the container.
# 暂停数据库容器db01提供服务。  
docker pause db01  
 
# 恢复数据库容器 db01 提供服务  
docker unpause db0

2. View process information running in the container (top)

# 查看容器mymysql的进程信息。  
docker top mymysql  
 
# 查看所有运行容器的进程信息。  
for i in  `docker ps |grep Up|awk '{print $1}'`;do echo \ &&docker top $i; done

3. Get real-time events (events)

  • -f: Filter events based on conditions;
  • –since: Display all events since the specified timestamp;
  • –until: Display the running time until the specified time;
# 显示docker 2016年7月1日后的所有事件。  
docker events  --since="1467302400"  
 
# 显示docker 镜像为mysql:5.6 2016年7月1日后的相关事件。  
docker events -f "image"="mysql:5.6" --since="1467302400"

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

4. Get the container’s logs (logs)

logs parameter description:

  • -f : Trace log output
  • –since : Display all logs from a certain start time
  • -t: display timestamp
  • –tail: List only the latest N container logs
# 跟踪查看容器mynginx的日志输出。  
docker logs -f mynginx  
 
# 查看容器mynginx从2016年7月1日后的最新10条日志。  
docker logs --since="2016-07-01" --tail=10 mynginx

5. Export the file system as a tar archive to STDOUT (export)

  • -o : Write input content to file.
# 将id为a404c6c174a2的容器按日期保存为tar文件。  
docker export -o mysql-`date +%Y%m%d`.tar a404c6c174a2  
 
ls mysql-`date +%Y%m%d`.tar

6. Create a new image from the container (commit)

  • -a: The submitted image author;

  • -c: Use Dockerfile instructions to create the image;

  • m: Description text when submitting;

  • -p: Pause the container when committing.

# 将容器a404c6c174a2 保存为新的镜像,
# 并添加提交人信息和说明信息。  
docker commit -a "gee" -m "my db" a404c6c174a2  mymysql:v1

7. Data copy (cp) between container and host

  • -L : keep links in source target
# 将主机/www/runoob目录拷贝到容器96f7f14e99ab的/www目录下。  
docker cp /www/runoob 96f7f14e99ab:/www/  
 
# 将主机/www/runoob目录拷贝到容器96f7f14e99ab中,目录重命名为www。  
docker cp /www/runoob 96f7f14e99ab:/www  
 
# 将容器96f7f14e99ab的/www目录拷贝到主机的/tmp目录中。  
docker cp  96f7f14e99ab:/www /tmp/

8. Check for changes in the file structure in the container (diff)

# 查看容器mymysql的文件结构更改。  
docker diff mymysql

9. Pull or update the specified image from the image warehouse (pull)

Parameter Description:

  • -a : Pull all tagged images
  • –disable-content-trust: Ignore image verification, enabled by default
# 从Docker Hub下载java最新版镜像。  
docker pull java  
# 从Docker Hub下载REPOSITORY为java的所有镜像。  
docker pull -a java

10. To upload the local image to the mirror warehouse, you must first log in to the mirror warehouse (push)

Parameter Description:

  • –disable-content-trust: Ignore image verification, enabled by default
# 上传本地镜像myapache:v1到镜像仓库中。  
docker push myapache:v1

11. Save the specified image into a tar archive file (save)

Parameter Description:

  • -o: The file to output to.
# 将镜像 runoob/ubuntu:v3 生成 my_ubuntu_v3.tar 文档  
docker save -o my_ubuntu_v3.tar runoob/ubuntu:v3

12. Import the image exported using the docker save command (load)

Parameter Description:

  • –input, -i: Specify the imported file instead of STDIN.
  • –quiet, -q: Streamline output information.
# 导入镜像  
docker load --input fedora.tar

13. Create an image from the archive (import)

Parameter Description:

  • -c: Use the docker command to create an image;
  • -m: Description text when submitting;
# 从镜像归档文件my_ubuntu_v3.tar创建镜像,命名为runoob/ubuntu:v4  
docker import  my_ubuntu_v3.tar runoob/ubuntu:v4

13. The docker container cannot be started after the firewall is restarted.

Because docker is highly dependent on iptables, you need to restart the docker service and re-enable the container after restarting the firewall or modifying the firewall.

  • First, check if iptables has a used port or something. If the container cannot be started because the port is disabled, you need to release it first and then restart it.
iptables -nvL

Insert image description here

  • Restart docker
systemctl restart docker

Guess you like

Origin blog.csdn.net/weixin_43576565/article/details/132305267