码头工人安装

[电子邮件 protected]:/# curl -sSL //get.docker.com/ | sh 

常用Docker命令

  • 码头工人–版本
  • 码头工人拉<image name>
  • docker运行-it -d<image name>
  • 码头工人ps
  • 泊坞窗ps -a   //show all the running 和 exited containers
  • docker exec -it<container name> /bin/bash
  • 码头工人停止
  • 码头工人杀   //通过立即停止执行来杀死容器
  • 码头工人提交   //在本地系统上创建已编辑容器的新映像
  • 码头工人登录     //登录Docker Hub仓库
  • 码头工人推<username/image name>    //将映像推送到Docker Hub存储库
  • 码头工人图像    //列出所有本地存储的docker映像
  • 码头工人<container id>
  • 码头工人rmi<image-id>
  • 码头工人<path to docker file>     //从指定的docker文件构建映像

[[电子邮件 protected] 撰写]# docker日志–tail 50 –follow –timestamps compose_db_1
2020-03-17T15:24:42.758002000Z chown:更改“ / var / lib / postgresql / data”的所有权:权限被拒绝
2020-03-17T15:24:43.410251000Z chown:更改“ / var / lib / postgresql / data”的所有权:权限被拒绝

Backup image 和 load the backup

[电子邮件 protected]:~# 码头工人图像
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
wordpress             latest              0d205d4886fe        2 weeks ago         540MB
nginx                 latest              ed21b7a8aee9        2 weeks ago         127MB
mysql                 5.7                 413be204e9c3        2 weeks ago         456MB
mariadb               latest              37f5f0a258bf        4 weeks ago         356MB
portainer/portainer   latest              2869fc110bf7        4 weeks ago         78.6MB
[电子邮件 protected]:~# docker save -o /root/nginx.tar nginx
[电子邮件 protected]:~# ls
nginx.tar  snap
[电子邮件 protected]:~#

您可以将此tar文件加载到其他计算机的图像列表中:

[电子邮件 protected]:~# docker load -i /root/nginx.tar

出口 容器/导入到图像 

docker export / docker import and docker save / docker load 服务于不同的目的。
docker export (和导入)是用于导出/导入容器的根文件系统的命令;从命令的“帮助”输出中;
出口 a container's filesystem as a tar archive
运行这些命令时, 您只会获得容器文件系统的归档文件,而不会得到映像的配置文件(例如 CMDENTRYPOINT and ENV).
的 docker save / docker load 另一方面,您可以使用命令保存/加载图像,包括其配置。从命令描述中;使用这些命令,您可以在Docker主机之间传输映像(无需使用注册表),并保留层和映像配置。
[电子邮件 protected]:~# docker container list
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                         NAMES
7f2118c12a0f        nginx:latest                 "nginx -g 'daemon of…"   7 days ago          Up 7 days           0.0.0.0:80->80/tcp, 443/tcp   Nginx1
58984786a347        wordpress:latest             "docker-entrypoint.s…"   7 days ago          Up 7 days           0.0.0.0:10000->80/tcp         51sec_wordpress_1
986469bf37d1        mysql:5.7                    "docker-entrypoint.s…"   7 days ago          Up 7 days           3306/tcp, 33060/tcp           51sec_db_1
e1965b3d6e1f        portainer/portainer:latest   "/portainer"             7 days ago          Up 7 days           0.0.0.0:9000->9000/tcp        portainer
[电子邮件 protected]:~# 码头工人停止 Nginx1
Nginx1
[电子邮件 protected]:~# 泊坞窗ps -a
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS                      PORTS                    NAMES
7f2118c12a0f        nginx:latest                 "nginx -g 'daemon of…"   7 days ago          Exited (0) 14 seconds ago                            Nginx1
58984786a347        wordpress:latest             "docker-entrypoint.s…"   7 days ago          Up 7 days                   0.0.0.0:10000->80/tcp    51sec_wordpress_1
986469bf37d1        mysql:5.7                    "docker-entrypoint.s…"   7 days ago          Up 7 days                   3306/tcp, 33060/tcp      51sec_db_1
e1965b3d6e1f        portainer/portainer:latest   "/portainer"             7 days ago          Up 7 days                   0.0.0.0:9000->9000/tcp   portainer
[电子邮件 protected]:~# docker export Nginx1 > /root/Container-Nginx1.tar
[电子邮件 protected]:~# 码头工人Nginx1
Nginx1
[电子邮件 protected]:~# 泊坞窗ps -a
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                    NAMES
58984786a347        wordpress:latest             "docker-entrypoint.s…"   7 days ago          Up 7 days           0.0.0.0:10000->80/tcp    51sec_wordpress_1
986469bf37d1        mysql:5.7                    "docker-entrypoint.s…"   7 days ago          Up 7 days           3306/tcp, 33060/tcp      51sec_db_1
e1965b3d6e1f        portainer/portainer:latest   "/portainer"             7 days ago          Up 7 days           0.0.0.0:9000->9000/tcp   portainer
[电子邮件 protected]:~# docker import /root/Container-Nginx1.tar Nginx1
invalid reference format: repository name must be lowercase
[电子邮件 protected]:~# docker import /root/Container-Nginx1.tar nginx1
sha256:df44fea67db399580e7cbdd5d09bd882c91bfe96d43c4b0c0f639aa7f74c9e20
[电子邮件 protected]:~# 泊坞窗ps -a
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                    NAMES
58984786a347        wordpress:latest             "docker-entrypoint.s…"   7 days ago          Up 7 days           0.0.0.0:10000->80/tcp    51sec_wordpress_1
986469bf37d1        mysql:5.7                    "docker-entrypoint.s…"   7 days ago          Up 7 days           3306/tcp, 33060/tcp      51sec_db_1
e1965b3d6e1f        portainer/portainer:latest   "/portainer"             7 days ago          Up 7 days           0.0.0.0:9000->9000/tcp   portainer

[电子邮件 protected]:~# 码头工人图像
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
nginx1                latest              df44fea67db3        7 minutes ago       143MB
wordpress             latest              0d205d4886fe        2 weeks ago         540MB
nginx                 latest              ed21b7a8aee9        2 weeks ago         127MB
mysql                 5.7                 413be204e9c3        2 weeks ago         456MB
mariadb               latest              37f5f0a258bf        4 weeks ago         356MB
portainer/portainer   latest              2869fc110bf7        4 weeks ago         78.6MB

[电子邮件 protected]:~# docker run -d --name Nginx1 --restart=always -p 80:80 nginx1
docker: Error response from daemon: No command specified.
See 'docker run --help'.

使用容器创建自己的图像

[电子邮件 protected]:~# docker container ps
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                    NAMES
0457b6159da9        nginx:latest                 "nginx -g 'daemon of…"   16 minutes ago      Up 5 minutes        0.0.0.0:80->80/tcp       nginx1
58984786a347        wordpress:latest             "docker-entrypoint.s…"   7 days ago          Up 7 days           0.0.0.0:10000->80/tcp    51sec_wordpress_1
986469bf37d1        mysql:5.7                    "docker-entrypoint.s…"   7 days ago          Up 7 days           3306/tcp, 33060/tcp      51sec_db_1
e1965b3d6e1f        portainer/portainer:latest   "/portainer"             7 days ago          Up 7 days           0.0.0.0:9000->9000/tcp   portainer
[电子邮件 protected]:~# 码头工人提交 nginx1 nginx1netsec
sha256:0cf3a7c347f9bca870bd97b9e40bfc11e959e8220e4529d49e4f452cd5de8e68
[电子邮件 protected]:~# docker image list
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
nginx1netsec          latest              0cf3a7c347f9        6 seconds ago       145MB
nginx                 latest              e791337790a6        3 days ago          127MB
wordpress             latest              0d205d4886fe        2 weeks ago         540MB
nginx                 <none>              ed21b7a8aee9        2 weeks ago         127MB
mysql                 5.7                 413be204e9c3        2 weeks ago         456MB
mariadb               latest              37f5f0a258bf        4 weeks ago         356MB
portainer/portainer   latest              2869fc110bf7        4 weeks ago         78.6MB
[电子邮件 protected]:~# 码头工人停止 nginx1
nginx1

[电子邮件 protected]:~# docker run --name nginx2 --restart=always -p 80:80 -d nginx1netsec
5fbe841d1f407db372ef8a69fe5295900b3b5b8eeea7d6d7be45f7eed247a19c
[电子邮件 protected]:~#
[电子邮件 protected]:~# docker container ps
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                    NAMES
5fbe841d1f40        nginx1netsec                 "nginx -g 'daemon of…"   2 minutes ago       Up 2 minutes        0.0.0.0:80->80/tcp       nginx2
58984786a347        wordpress:latest             "docker-entrypoint.s…"   7 days ago          Up 7 days           0.0.0.0:10000->80/tcp    51sec_wordpress_1
986469bf37d1        mysql:5.7                    "docker-entrypoint.s…"   7 days ago          Up 7 days           3306/tcp, 33060/tcp      51sec_db_1
e1965b3d6e1f        portainer/portainer:latest   "/portainer"             7 days ago          Up 7 days           0.0.0.0:9000->9000/tcp   portainer
[电子邮件 protected]:~#


这样,即使是搬运工,也仍然可以管理这个新容器。

将自己的Docker映像发布到Docker Hub


[电子邮件 protected]:~# 码头工人登录
Login with your 码头工人 ID to push 和 pull images from 码头工人 Hub. If you don't have a 码头工人 ID, head over to //hub.docker.com to create 上e.
Username: 约翰yan2
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
//docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

[电子邮件 protected]:~# docker tag nginx1netsec 约翰yan2/nginx1netsec:latest
[电子邮件 protected]:~# 码头工人推johnyan2/nginx1netsec:latest的 push refers to repository [docker.io/johnyan2/nginx1netsec]
a0ad3b8aa236: Pushed
be91fceb796e: Pushed
919b6770519b: Pushed
b60e5c3bcef2: Pushed
latest: digest: sha256:2ccc1aeb4d69052c9afb6f36a5881bc6b4faf43bc86e33d6922f33382b5bbc28 size: 1160


Pull 和 run your own 码头工人:


$ 码头工人拉johnyan2/nginx1netsec
Using default tag: latest
latest: Pulling from 约翰yan2/nginx1netsec
123275d6e508: Already exists 
6cd6a943ce27: Already exists 
a50b5ac4a7fb: Already exists 
75facb91406e: Pull complete 
Digest: sha256:2ccc1aeb4d69052c9afb6f36a5881bc6b4faf43bc86e33d6922f33382b5bbc28
Status: Downloaded newer image for 约翰yan2/nginx1netsec:latest
docker.io/johnyan2/nginx1netsec:latest
[node1] (local) [电子邮件 protected] ~
$ docker image list
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
约翰yan2/nginx1netsec   latest              0cf3a7c347f9        11 hours ago        145MB
nginx                   latest              e791337790a6        4 days ago          127MB
[node1] (local) [电子邮件 protected] ~
$ docker run  -p 80:80 --name Nginx1 -d 约翰yan2/nginx1netsec
a4e00ef3a26aede705f6519d34baeab2045b31153a4ad2b1a75bb1ec928d27f5
[node1] (local) [电子邮件 protected] ~
$ netstat -lantp
Active Internet connections (servers 和 established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.11:35667        0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      36/sshd
tcp        0      0 :::22                   :::*                    LISTEN      36/sshd
tcp        0      0 :::2375                 :::*                    LISTEN      20/dockerd
tcp        0      0 :::80                   :::*                    LISTEN      2283/docker-proxy
tcp        0      0 ::ffff:172.18.0.24:2375 ::ffff:172.18.0.1:39999 ESTABLISHED 20/dockerd
tcp        0      0 ::ffff:172.18.0.24:2375 ::ffff:172.18.0.1:39823 ESTABLISHED 20/dockerd
[node1] (local) [电子邮件 protected] ~

故障排除

[node1] (local) [电子邮件 protected] ~
$ ./minkebox.sh 172.18.0.22 /var/data
minke
docker: Error response from daemon: path /var/data is mounted 上 / but it is not a shared mount.

[node1] (local) [电子邮件 protected] ~
$ mount --make-shared /
[node1] (local) [电子邮件 protected] ~
$ ./minkebox.sh 172.18.0.22 /var/data
minke
[node1] (local) [电子邮件 protected] ~





参考文献

通过 约翰

发表评论