docker华为云
使用公共Registry-华为云
登录华为云
选择区域,选择离自己近的数据中心,创建组织
进入新创建的组织
接下来登录华为云,上传自己的镜像
复制登录指令
通过上面获取的登录指令,回到docker上登陆

[root@docker ~ 09:43:14]# docker login -u cn-east-3@HST3WFZ7NAO4EPIC34H6 -p a053b8741de374dea23d4a0afa27873f0b7fa6da42806498da82464e945fa259 swr.cn-east-3.myhuaweicloud.com
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@docker ~ 10:05:15]# docker images httpd:centos
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd centos 1fd2344332e6 42 hours ago 253MB
[root@docker ~ 10:05:48]# docker tag httpd:centos swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd:v1[root@docker ~ 10:07:06]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centosjava8 461 1846f520e9a7 41 hours ago 537MB
httpd centos 1fd2344332e6 42 hours ago 253MB
swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd v1 1fd2344332e6 42 hours ago 253MB
centos ssh 29a83cb13ca9 42 hours ago 283MB
my-image latest 358f35e5adf2 47 hours ago 4.42MB
image-debug latest d9f1f51394d4 47 hours ago 4.42MB
xmy v2 d9f1f51394d4 47 hours ago 4.42MB
vim-1-dockerfile-3 latest 9d071477d1b7 47 hours ago 213MB
vim-1-dockerfile-2 latest bcc3d0fd9fb9 47 hours ago 213MB
vim-1 latest 5e42e96ce759 2 days ago 213MB
vim latest 7a12be773edc 2 days ago 100MB
ubuntu-with-vim-dockerfile latest 5081df56d3d7 2 days ago 213MB
vim-1-dockerfile latest 5081df56d3d7 2 days ago 213MB
httpd latest 58d56e9057ae 5 days ago 117MB
ubuntu latest 30ba44506a6d 2 weeks ago 100MB
dockerfile2 latest 778b52143a69 19 months ago 4.42MB
<none> <none> 72ac116e2bd9 19 months ago 4.42MB
centos.ssh.dockerfile latest 124ba07f6cf0 19 months ago 4.42MB
dockerfile7 latest 124ba07f6cf0 19 months ago 4.42MB
dockerfile5 latest 9ff0c8a8f5a9 19 months ago 4.42MB
dockerfile3 latest 41b72d7c2c45 19 months ago 4.42MB
dockerfile1 latest c1b8220c6083 19 months ago 4.42MB
dockerfile6 latest ca804453d33a 19 months ago 4.42MB
centos 7 eeb6ee3f44bd 4 years ago 204MB
[root@docker ~ 10:07:12]# docker push swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd:v1
The push refers to repository [swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd]
48a58c9ec3a2: Pushed
3c9b803541ab: Pushed
51ed102360a7: Pushed
74ddd0ec08fa: Pushed
v1: digest: sha256:1a5a7e17f84f74ea066ddb15fd4e13a7eb70169d27d0e15da8891ec27988cb3c size: 1155
[root@docker ~ 10:08:21]# dockerrmiswr.cn-east-
-bash: dockerrmiswr.cn-east-: command not found
[root@docker ~ 10:10:03]# docker rmi swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd:v1
Untagged: swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd:v1
Untagged: swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd@sha256:1a5a7e17f84f74ea066ddb15fd4e13a7eb70169d27d0e15da8891ec27988cb3c
[root@docker ~ 10:10:19]# docker pull swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd:v1
v1: Pulling from mymy/centos_httpd
Digest: sha256:1a5a7e17f84f74ea066ddb15fd4e13a7eb70169d27d0e15da8891ec27988cb3c
Status: Downloaded newer image for swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd:v1
swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd:v1
[root@docker ~ 10:10:51]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centosjava8 461 1846f520e9a7 41 hours ago 537MB
httpd centos 1fd2344332e6 42 hours ago 253MB
swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd v1 1fd2344332e6 42 hours ago 253MB
centos ssh 29a83cb13ca9 42 hours ago 283MB
my-image latest 358f35e5adf2 47 hours ago 4.42MB
image-debug latest d9f1f51394d4 47 hours ago 4.42MB
xmy v2 d9f1f51394d4 47 hours ago 4.42MB
vim-1-dockerfile-3 latest 9d071477d1b7 47 hours ago 213MB
vim-1-dockerfile-2 latest bcc3d0fd9fb9 2 days ago 213MB
vim-1 latest 5e42e96ce759 2 days ago 213MB
vim latest 7a12be773edc 2 days ago 100MB
ubuntu-with-vim-dockerfile latest 5081df56d3d7 2 days ago 213MB
vim-1-dockerfile latest 5081df56d3d7 2 days ago 213MB
httpd latest 58d56e9057ae 5 days ago 117MB
ubuntu latest 30ba44506a6d 2 weeks ago 100MB
dockerfile6 latest ca804453d33a 19 months ago 4.42MB
<none> <none> 72ac116e2bd9 19 months ago 4.42MB
centos.ssh.dockerfile latest 124ba07f6cf0 19 months ago 4.42MB
dockerfile7 latest 124ba07f6cf0 19 months ago 4.42MB
dockerfile3 latest 41b72d7c2c45 19 months ago 4.42MB
dockerfile5 latest 9ff0c8a8f5a9 19 months ago 4.42MB
dockerfile1 latest c1b8220c6083 19 months ago 4.42MB
dockerfile2 latest 778b52143a69 19 months ago 4.42MB
centos 7 eeb6ee3f44bd 4 years ago 204MB
设为公开后下载指令如下:

020 搭建本地Registry
Docker Hub虽然方便,但是有限制
- 需要 internet 连接,而且下载和上传速度慢。
- 上传到 Docker Hub 的镜像任何人都能够访问,虽然可以用私有 repository,但不是免费的。
- 安全原因很多组织不允许将镜像放到外网。
解决方案就是搭建本地的 Registry。
Registry
Docker 已经将 Registry 开源了,同时在 Docker Hub 上也有官方的镜像 registry。下面我们就在
Docker 中运行自己的 registry。
[root@docker ~ 10:18:44]# docker run -d -p 5000:5000 -v /myregistry:/var/lib/registry registry:2
Unable to find image 'registry:2' locally
2: Pulling from library/registry
44cf07d57ee4: Pull complete
bbbdd6c6894b: Pull complete
8e82f80af0de: Pull complete
3493bf46cdec: Pull complete
6d464ea18732: Pull complete
Digest: sha256:a3d8aaa63ed8681a604f1dea0aa03f100d5895b6a58ace528858a7b332415373
Status: Downloaded newer image for registry:2
71c954ccfabbdf97ebd29ee2d196d3f209ccc2c4f93b90194b671f7711289183
[root@docker ~ 10:29:07]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centosjava8 461 1846f520e9a7 42 hours ago 537MB
httpd centos 1fd2344332e6 43 hours ago 253MB
swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd v1 1fd2344332e6 43 hours ago 253MB
centos ssh 29a83cb13ca9 43 hours ago 283MB
my-image latest 358f35e5adf2 47 hours ago 4.42MB
image-debug latest d9f1f51394d4 2 days ago 4.42MB
xmy v2 d9f1f51394d4 2 days ago 4.42MB
vim-1-dockerfile-3 latest 9d071477d1b7 2 days ago 213MB
vim-1-dockerfile-2 latest bcc3d0fd9fb9 2 days ago 213MB
vim-1 latest 5e42e96ce759 2 days ago 213MB
vim latest 7a12be773edc 2 days ago 100MB
ubuntu-with-vim-dockerfile latest 5081df56d3d7 2 days ago 213MB
vim-1-dockerfile latest 5081df56d3d7 2 days ago 213MB
httpd latest 58d56e9057ae 5 days ago 117MB
ubuntu latest 30ba44506a6d 2 weeks ago 100MB
dockerfile6 latest ca804453d33a 19 months ago 4.42MB
dockerfile2 latest 778b52143a69 19 months ago 4.42MB
dockerfile3 latest 41b72d7c2c45 19 months ago 4.42MB
dockerfile5 latest 9ff0c8a8f5a9 19 months ago 4.42MB
centos.ssh.dockerfile latest 124ba07f6cf0 19 months ago 4.42MB
dockerfile7 latest 124ba07f6cf0 19 months ago 4.42MB
dockerfile1 latest c1b8220c6083 19 months ago 4.42MB
<none> <none> 72ac116e2bd9 19 months ago 4.42MB
registry 2 26b2eb03618e 2 years ago 25.4MB
centos 7 eeb6ee3f44bd 4 years ago 204MB
[root@docker ~ 10:29:25]# docker tag httpd:latest localhost:5000/httpd:v1
[root@docker ~ 10:30:06]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centosjava8 461 1846f520e9a7 42 hours ago 537MB
httpd centos 1fd2344332e6 43 hours ago 253MB
swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd v1 1fd2344332e6 43 hours ago 253MB
centos ssh 29a83cb13ca9 43 hours ago 283MB
my-image latest 358f35e5adf2 47 hours ago 4.42MB
image-debug latest d9f1f51394d4 2 days ago 4.42MB
xmy v2 d9f1f51394d4 2 days ago 4.42MB
vim-1-dockerfile-3 latest 9d071477d1b7 2 days ago 213MB
vim-1-dockerfile-2 latest bcc3d0fd9fb9 2 days ago 213MB
vim-1 latest 5e42e96ce759 2 days ago 213MB
vim latest 7a12be773edc 2 days ago 100MB
ubuntu-with-vim-dockerfile latest 5081df56d3d7 2 days ago 213MB
vim-1-dockerfile latest 5081df56d3d7 2 days ago 213MB
httpd latest 58d56e9057ae 5 days ago 117MB
localhost:5000/httpd v1 58d56e9057ae 5 days ago 117MB
ubuntu latest 30ba44506a6d 2 weeks ago 100MB
dockerfile6 latest ca804453d33a 19 months ago 4.42MB
dockerfile2 latest 778b52143a69 19 months ago 4.42MB
dockerfile3 latest 41b72d7c2c45 19 months ago 4.42MB
centos.ssh.dockerfile latest 124ba07f6cf0 19 months ago 4.42MB
dockerfile7 latest 124ba07f6cf0 19 months ago 4.42MB
<none> <none> 72ac116e2bd9 19 months ago 4.42MB
dockerfile5 latest 9ff0c8a8f5a9 19 months ago 4.42MB
dockerfile1 latest c1b8220c6083 19 months ago 4.42MB
registry 2 26b2eb03618e 2 years ago 25.4MB
centos 7 eeb6ee3f44bd 4 years ago 204MB
[root@docker ~ 10:30:09]# docker push localhost:5000/httpd:v1
The push refers to repository [localhost:5000/httpd]
9f2766e38b5a: Pushed
21083e64fdeb: Pushed
8f2c78d3000e: Pushed
5f70bf18a086: Pushed
a9c7ebf41049: Pushed
6d7c150df58d: Pushed
v1: digest: sha256:d505d46934d1727c62b78cf5e52d363fd26171c4dc465d9f566dcc7c79f03147 size: 1572
[root@docker ~ 10:30:59]# curl http://localhost:5000/v2/_catalog
{"repositories":["httpd"]}
[root@docker ~ 10:31:44]# docker pull localhost:5000/httpd:v1
v1: Pulling from httpd
Digest: sha256:d505d46934d1727c62b78cf5e52d363fd26171c4dc465d9f566dcc7c79f03147
Status: Image is up to date for localhost:5000/httpd:v1
localhost:5000/httpd:v1
[root@docker ~ 10:32:00]# docker images localhost:5000/httpd
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost:5000/httpd v1 58d56e9057ae 5 days ago 117MB
除了镜像的名称长一些(包含 registry host 和 port),使用方式完全一样。
以上是搭建本地 registry 的简要步骤。当然 registry 也支持认证,https 安全传输等特性,具体可以参考
官方文档https://docs.docker.com/registry/configuration/
企业级私有仓库Harbor
我们如果需要部署一个私有镜像仓库来使用,最简单的就是 registry ,一行命令就可以运行在 Docker
中,但功能也比较弱,如果想要私有镜像仓库功能更丰富些,可以使用 Harbor。
本文简单介绍下 Harbor 的安装和使用。
Harbor是构建企业级私有docker镜像的仓库的开源解决方案,它是Docker Registry的更高级封装,除了
提供友好的Web UI界面,角色和用户权限管理,用户操作审计等功能外,它还整合了K8s的插件(Add-
ons)仓库。
harbor下载:https://github.com/goharbor/harbor/releases
安装
[root@docker ~ 10:32:17]# ls
'=' harbor-offline-installer-v2.9.1.tgz passwd.tar.gz
anaconda-ks.cfg httpd.dockerfile testfile
CACHED index.html tmpfile2
centos.ssh.dockerfile '[internal]' transferring
Dockerfile myfile writing
exporting naming 'ystemctl restart docker'
[root@docker ~ 11:00:10]# tar -xvf harbor-offline-installer-v2.9.1.tgz
harbor/harbor.v2.9.1.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/common.sh
harbor/harbor.yml.tmpl
[root@docker ~ 11:00:44]# mkdir /opt/harbor
[root@docker ~ 11:01:03]# mv harbor/* /opt/harbor/
[root@docker ~ 11:01:19]# cd /opt/harbor/
[root@docker harbor 11:01:28]# docker load -i harbor.v2.9.1.tar.gz
a1dcbad8836c: Loading layer 40.11MB/40.11MB
4349dad1c75c: Loading layer 10.89MB/10.89MB
b3619b11127a: Loading layer 3.584kB/3.584kB
7b38a647487c: Loading layer 2.56kB/2.56kB
af63cee918f4: Loading layer 44.69MB/44.69MB
087e0e1d01ed: Loading layer 45.48MB/45.48MB
Loaded image: goharbor/harbor-jobservice:v2.9.1
7a18cae000bb: Loading layer 7.873MB/7.873MB
6e8443cb30ea: Loading layer 4.096kB/4.096kB
7e6f1921b03b: Loading layer 17.4MB/17.4MB
7ab103a3c9e9: Loading layer 3.072kB/3.072kB
afdeb50007ba: Loading layer 32.78MB/32.78MB
0838cfee6fc3: Loading layer 50.97MB/50.97MB
Loaded image: goharbor/harbor-registryctl:v2.9.1
06a21a75ac76: Loading layer 10.89MB/10.89MB
7ef38c74aa21: Loading layer 3.584kB/3.584kB
78e12b1b294b: Loading layer 2.56kB/2.56kB
7415bb76ee07: Loading layer 58.23MB/58.23MB
c25cd46ee82a: Loading layer 5.632kB/5.632kB
1a3de5a9a094: Loading layer 122.4kB/122.4kB
2d2d193fbdcd: Loading layer 80.38kB/80.38kB
ee47e7543fea: Loading layer 59.23MB/59.23MB
6ebe4d7b431b: Loading layer 2.56kB/2.56kB
Loaded image: goharbor/harbor-core:v2.9.1
7d9f76d29c1c: Loading layer 124.4MB/124.4MB
50cb5ae20a44: Loading layer 3.584kB/3.584kB
59a78c21122c: Loading layer 3.072kB/3.072kB
6beb01cc5baa: Loading layer 2.56kB/2.56kB
b09018e5a73f: Loading layer 3.072kB/3.072kB
c1078fb9f5c7: Loading layer 3.584kB/3.584kB
59dadef71b1b: Loading layer 20.48kB/20.48kB
Loaded image: goharbor/harbor-log:v2.9.1
d1de629330a4: Loading layer 60.48MB/60.48MB
3cb3537a6da7: Loading layer 173.9MB/173.9MB
a327f18369ed: Loading layer 25.46MB/25.46MB
3f5c8182a7a2: Loading layer 63.37MB/63.37MB
a972da56e974: Loading layer 5.12kB/5.12kB
2fa2fe9c942b: Loading layer 6.144kB/6.144kB
53214b04b836: Loading layer 3.072kB/3.072kB
7fde99a5b238: Loading layer 2.048kB/2.048kB
b985c63bb4f0: Loading layer 2.56kB/2.56kB
58e8be9a88e4: Loading layer 7.68kB/7.68kB
Loaded image: goharbor/harbor-db:v2.9.1
64966afbcdad: Loading layer 10.89MB/10.89MB
7ffad26c4cb7: Loading layer 27.62MB/27.62MB
ce5f177604e5: Loading layer 4.608kB/4.608kB
4c46c82379dc: Loading layer 28.41MB/28.41MB
Loaded image: goharbor/harbor-exporter:v2.9.1
f2d51adf2664: Loading layer 60.48MB/60.48MB
962114f3c6f4: Loading layer 110.8MB/110.8MB
fa9bce70fee8: Loading layer 3.072kB/3.072kB
034a19d4e2af: Loading layer 59.9kB/59.9kB
ea8a227a5ce4: Loading layer 61.95kB/61.95kB
Loaded image: goharbor/redis-photon:v2.9.1
b99018c986e9: Loading layer 115.1MB/115.1MB
Loaded image: goharbor/nginx-photon:v2.9.1
7e85bea4f9eb: Loading layer 7.873MB/7.873MB
2d7031c02133: Loading layer 4.096kB/4.096kB
f2f29a057a0e: Loading layer 3.072kB/3.072kB
c465d9ffbcae: Loading layer 17.4MB/17.4MB
e8392e2d1c5c: Loading layer 18.19MB/18.19MB
Loaded image: goharbor/registry-photon:v2.9.1
0ee5099becd4: Loading layer 8.424MB/8.424MB
709c954772b5: Loading layer 4.096kB/4.096kB
4b4592e67634: Loading layer 3.072kB/3.072kB
db64864bc2d4: Loading layer 196.4MB/196.4MB
b2e16fced657: Loading layer 14.21MB/14.21MB
261777ce207b: Loading layer 211.4MB/211.4MB
Loaded image: goharbor/trivy-adapter-photon:v2.9.1
8bb88f3b5655: Loading layer 89.16MB/89.16MB
58f41452397c: Loading layer 65.05MB/65.05MB
56353e1b0c2c: Loading layer 58.46MB/58.46MB
78dc49080966: Loading layer 65.54kB/65.54kB
f1e566e1fcc5: Loading layer 2.56kB/2.56kB
1baf36cc0bfd: Loading layer 1.536kB/1.536kB
4f36dbd6f970: Loading layer 12.29kB/12.29kB
0b3526c9e5d6: Loading layer 5.322MB/5.322MB
e7daf9b6bcbe: Loading layer 429.1kB/429.1kB
Loaded image: goharbor/prepare:v2.9.1
d0dcb5740755: Loading layer 115.1MB/115.1MB
a68394b34761: Loading layer 6.46MB/6.46MB
e47863752870: Loading layer 245.8kB/245.8kB
eb0d64571e29: Loading layer 1.233MB/1.233MB
Loaded image: goharbor/harbor-portal:v2.9.1
[root@docker harbor 11:02:33]# cp -ar harbor.yml.tmpl harbor.yml
[root@docker harbor 11:03:16]# vim harbor.yml
[root@docker harbor 11:04:24]# vim harbor.yml
[root@docker harbor 11:04:48]# ./prepare
prepare base dir is set to /opt/harbor
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
Generated and saved secret to file: /data/secret/keys/secretkey
Successfully called func: create_root_cert
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
[root@docker harbor 11:05:02]# ./install.sh
[Step 0]: checking if docker is installed ...
Note: docker version: 26.1.3
[Step 1]: checking docker-compose is installed ...
Note: Docker Compose version v2.27.0
[Step 2]: loading Harbor images ...
Loaded image: goharbor/harbor-jobservice:v2.9.1
Loaded image: goharbor/harbor-registryctl:v2.9.1
Loaded image: goharbor/harbor-core:v2.9.1
Loaded image: goharbor/harbor-log:v2.9.1
Loaded image: goharbor/harbor-db:v2.9.1
Loaded image: goharbor/harbor-exporter:v2.9.1
Loaded image: goharbor/redis-photon:v2.9.1
Loaded image: goharbor/nginx-photon:v2.9.1
Loaded image: goharbor/registry-photon:v2.9.1
Loaded image: goharbor/trivy-adapter-photon:v2.9.1
Loaded image: goharbor/prepare:v2.9.1
Loaded image: goharbor/harbor-portal:v2.9.1
[Step 3]: preparing environment ...
[Step 4]: preparing harbor configs ...
prepare base dir is set to /opt/harbor
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
Clearing the configuration file: /config/portal/nginx.conf
Clearing the configuration file: /config/log/logrotate.conf
Clearing the configuration file: /config/log/rsyslog_docker.conf
Clearing the configuration file: /config/nginx/nginx.conf
Clearing the configuration file: /config/core/env
Clearing the configuration file: /config/core/app.conf
Clearing the configuration file: /config/registry/passwd
Clearing the configuration file: /config/registry/config.yml
Clearing the configuration file: /config/registryctl/env
Clearing the configuration file: /config/registryctl/config.yml
Clearing the configuration file: /config/db/env
Clearing the configuration file: /config/jobservice/env
Clearing the configuration file: /config/jobservice/config.yml
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
loaded secret from file: /data/secret/keys/secretkey
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
Note: stopping existing Harbor instance ...
WARN[0000] /opt/harbor/docker-compose.yml: `version` is obsolete
[Step 5]: starting Harbor ...
WARN[0000] /opt/harbor/docker-compose.yml: `version` is obsolete
[+] Running 10/10
✔ Network harbor_harbor Created 0.3s
✔ Container harbor-log Started 0.8s
✔ Container harbor-db Started 2.6s
✔ Container harbor-portal Started 2.0s
✔ Container registryctl Started 2.6s
✔ Container registry Started 1.7s
✔ Container redis Started 2.6s
✔ Container harbor-core Started 3.4s
✔ Container nginx Started 4.9s
✔ Container harbor-jobservice Started 4.7s
✔ ----Harbor has been installed and started successfully.----
harbor.yum
# Configuration file of Harbor
# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname: 192.168.108.30
# http related config
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
port: 80
# https related config
#https:
# https port for harbor, default is 443
# port: 443
# The path of cert and key files for nginx
#certificate: /your/certificate/path
#private_key: /your/private/key/path
# # Uncomment following will enable tls communication between all harbor components
# internal_tls:
# # set enabled to true means internal tls is enabled
# The initial password of Harbor admin
# It only works in first time to install harbor
# Remember Change the admin password from UI after launching Harbor.
harbor_admin_password: huawei

[root@docker harbor 11:12:21]# vim /etc/docker/daemon.json
[root@docker harbor 11:30:52]# systemctl restart docker
[root@docker harbor 11:31:24]# ./install.sh
[Step 0]: checking if docker is installed ...
Note: docker version: 26.1.3
[Step 1]: checking docker-compose is installed ...
Note: Docker Compose version v2.27.0
[Step 2]: loading Harbor images ...
Loaded image: goharbor/harbor-jobservice:v2.9.1
Loaded image: goharbor/harbor-registryctl:v2.9.1
Loaded image: goharbor/harbor-core:v2.9.1
Loaded image: goharbor/harbor-log:v2.9.1
Loaded image: goharbor/harbor-db:v2.9.1
Loaded image: goharbor/harbor-exporter:v2.9.1
Loaded image: goharbor/redis-photon:v2.9.1
Loaded image: goharbor/nginx-photon:v2.9.1
Loaded image: goharbor/registry-photon:v2.9.1
Loaded image: goharbor/trivy-adapter-photon:v2.9.1
Loaded image: goharbor/prepare:v2.9.1
Loaded image: goharbor/harbor-portal:v2.9.1
[Step 3]: preparing environment ...
[Step 4]: preparing harbor configs ...
prepare base dir is set to /opt/harbor
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
Clearing the configuration file: /config/portal/nginx.conf
Clearing the configuration file: /config/log/logrotate.conf
Clearing the configuration file: /config/log/rsyslog_docker.conf
Clearing the configuration file: /config/nginx/nginx.conf
Clearing the configuration file: /config/core/env
Clearing the configuration file: /config/core/app.conf
Clearing the configuration file: /config/registry/passwd
Clearing the configuration file: /config/registry/config.yml
Clearing the configuration file: /config/registry/root.crt
Clearing the configuration file: /config/registryctl/env
Clearing the configuration file: /config/registryctl/config.yml
Clearing the configuration file: /config/db/env
Clearing the configuration file: /config/jobservice/env
Clearing the configuration file: /config/jobservice/config.yml
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
loaded secret from file: /data/secret/keys/secretkey
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
Note: stopping existing Harbor instance ...
WARN[0000] /opt/harbor/docker-compose.yml: `version` is obsolete
[+] Running 10/10
✔ Container nginx Removed 0.0s
✔ Container registryctl Removed 0.0s
✔ Container harbor-jobservice Removed 0.0s
✔ Container harbor-portal Removed 0.0s
✔ Container harbor-core Removed 0.0s
✔ Container harbor-db Removed 0.0s
✔ Container registry Removed 0.1s
✔ Container redis Removed 0.0s
✔ Container harbor-log Removed 10.2s
✔ Network harbor_harbor Removed 0.2s
[Step 5]: starting Harbor ...
WARN[0000] /opt/harbor/docker-compose.yml: `version` is obsolete
[+] Running 10/10
✔ Network harbor_harbor Created 0.3s
✔ Container harbor-log Started 0.8s
✔ Container registryctl Started 2.6s
✔ Container redis Started 2.7s
✔ Container registry Started 2.0s
✔ Container harbor-portal Started 2.5s
✔ Container harbor-db Started 1.7s
✔ Container harbor-core Started 3.3s
✔ Container nginx Started 4.8s
✔ Container harbor-jobservice Started 4.6s
✔ ----Harbor has been installed and started successfully.----
[root@docker harbor 11:32:07]# docker login 192.168.108.30
Username: image_admin
Password:
Error response from daemon: Get "http://192.168.108.30/v2/": unauthorized:
[root@docker harbor 11:32:54]# docker login 192.168.108.30
Username: image_admin
Password:
Error response from daemon: Get "http://192.168.108.30/v2/": unauthorized:
[root@docker harbor 11:33:16]# vim /etc/docker/daemon.json
[root@docker harbor 11:35:58]# docker login 192.168.108.30
Username: images_admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@docker harbor 11:36:27]# cd ~/.docker/
[root@docker .docker 11:36:46]# pwd
/root/.docker
[root@docker .docker 11:36:49]# cat config.json
{
"auths": {
"192.168.108.30": {
"auth": "aW1hZ2VzX2FkbWluOkNsb3VkMTIjJA=="
},
"swr.cn-east-3.myhuaweicloud.com": {
"auth": "Y24tZWFzdC0zQEhTVDNXRlo3TkFPNEVQSUMzNEg2OmEwNTNiODc0MWRlMzc0ZGVhMjNkNGEwYWZhMjc4NzNmMGI3ZmE2ZGE0MjgwNjQ5OGRhODI0NjRlOTQ1ZmEyNTk="
}
}
}[root@docker .docker 11:36:54]#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centosjava8 461 1846f520e9a7 43 hours ago 537MB
httpd centos 1fd2344332e6 44 hours ago 253MB
swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd v1 1fd2344332e6 44 hours ago 253MB
centos ssh 29a83cb13ca9 44 hours ago 283MB
my-image latest 358f35e5adf2 2 days ago 4.42MB
image-debug latest d9f1f51394d4 2 days ago 4.42MB
xmy v2 d9f1f51394d4 2 days ago 4.42MB
vim-1-dockerfile-3 latest 9d071477d1b7 2 days ago 213MB
vim-1-dockerfile-2 latest bcc3d0fd9fb9 2 days ago 213MB
vim-1 latest 5e42e96ce759 2 days ago 213MB
vim latest 7a12be773edc 2 days ago 100MB
ubuntu-with-vim-dockerfile latest 5081df56d3d7 2 days ago 213MB
vim-1-dockerfile latest 5081df56d3d7 2 days ago 213MB
httpd latest 58d56e9057ae 5 days ago 117MB
localhost:5000/httpd v1 58d56e9057ae 5 days ago 117MB
ubuntu latest 30ba44506a6d 2 weeks ago 100MB
dockerfile3 latest 41b72d7c2c45 19 months ago 4.42MB
centos.ssh.dockerfile latest 124ba07f6cf0 19 months ago 4.42MB
dockerfile7 latest 124ba07f6cf0 19 months ago 4.42MB
dockerfile2 latest 778b52143a69 19 months ago 4.42MB
dockerfile1 latest c1b8220c6083 19 months ago 4.42MB
dockerfile5 latest 9ff0c8a8f5a9 19 months ago 4.42MB
dockerfile6 latest ca804453d33a 19 months ago 4.42MB
<none> <none> 72ac116e2bd9 19 months ago 4.42MB
goharbor/harbor-exporter v2.9.1 37bfd4fa26bc 2 years ago 105MB
goharbor/redis-photon v2.9.1 67827413c0fd 2 years ago 209MB
goharbor/trivy-adapter-photon v2.9.1 a02695b8f8ea 2 years ago 469MB
goharbor/harbor-registryctl v2.9.1 a076218bb631 2 years ago 148MB
goharbor/registry-photon v2.9.1 2f01ea8b1853 2 years ago 82.7MB
goharbor/nginx-photon v2.9.1 5200203dd7ef 2 years ago 153MB
goharbor/harbor-log v2.9.1 ac1cdcc94a5f 2 years ago 162MB
goharbor/harbor-jobservice v2.9.1 d9ff6fc98cc8 2 years ago 139MB
goharbor/harbor-core v2.9.1 0a3a7953409c 2 years ago 166MB
goharbor/harbor-portal v2.9.1 345284db8ca1 2 years ago 161MB
goharbor/harbor-db v2.9.1 69606d285be1 2 years ago 358MB
goharbor/prepare v2.9.1 adb2d804c458 2 years ago 253MB
registry 2 26b2eb03618e 2 years ago 25.4MB
centos 7 eeb6ee3f44bd 4 years ago 204MB
[root@docker .docker 11:38:03]# docker tag httpd 192.168.108.30/cloud/httpd
[root@docker .docker 11:38:53]# docker push 192.168.108.30/cloud/httpd
Using default tag: latest
The push refers to repository [192.168.108.30/cloud/httpd]
9f2766e38b5a: Pushed
21083e64fdeb: Pushed
8f2c78d3000e: Pushed
5f70bf18a086: Pushed
a9c7ebf41049: Pushed
6d7c150df58d: Pushed
latest: digest: sha256:d505d46934d1727c62b78cf5e52d363fd26171c4dc465d9f566dcc7c79f03147 size: 1572
[root@docker .docker 11:39:30]# docker pull 192.168.108.30/cloud/httpd:latest
latest: Pulling from cloud/httpd
Digest: sha256:d505d46934d1727c62b78cf5e52d363fd26171c4dc465d9f566dcc7c79f03147
Status: Image is up to date for 192.168.108.30/cloud/httpd:latest
192.168.108.30/cloud/httpd:latest
daemon.json
{
"insecure-registries":["192.168.108.30"],
"registry-mirrors": [
"https://054b8ac70e8010d90f2ac00ef29e6580.mirror.swr.myhuaweicloud.com" ]
}
~

卸载harbor
[root@docker .docker 11:45:47]# cd /opt/harbor/
[root@docker harbor 11:46:34]# docker compose down
WARN[0000] /opt/harbor/docker-compose.yml: `version` is obsolete
[+] Running 10/10
✔ Container registryctl Removed 0.3s
✔ Container nginx Removed 0.3s
✔ Container harbor-jobservice Removed 0.3s
✔ Container harbor-core Removed 0.2s
✔ Container harbor-portal Removed 0.2s
✔ Container redis Removed 0.2s
✔ Container harbor-db Removed 0.2s
✔ Container registry Removed 0.2s
✔ Container harbor-log Removed 10.1s
✔ Network harbor_harbor Removed 0.2s
[root@docker harbor 11:46:57]# docker images |grep harbor |awk '{print$1":"$2}' |xargs docker rmi
Untagged: goharbor/harbor-exporter:v2.9.1
Deleted: sha256:37bfd4fa26bc718e3342a9a33c9455e7d3b75a0c23bf459f5c5143531c0f698b
Deleted: sha256:ed3aee4feacf35eb4a2a2d3feae2d884ea19c76d0f3d49d821315ca25465f9ff
Deleted: sha256:c51b73e889f462a22228354385ae1f9547d84bb23b4e32071a624d9c0f90f4ec
Deleted: sha256:d78355f7df2a8dcc7d9e8d40462953bf095218a2e2a61dc27c16694b9e70b97c
Deleted: sha256:598f94871f984efd6ac9f01ca366cc80604e638af4bcf0ce2c928ae0c3fa7fa4
Untagged: goharbor/redis-photon:v2.9.1
Deleted: sha256:67827413c0fd3d6b24363950b7fbea54896975c9ccd50ddc7d51ea74fe7a1252
Deleted: sha256:87904c35cc24bfb92360a7f8e876e803112f74c7d8f704367107184017445013
Deleted: sha256:63bfed08841949e7a4edc09aefa46fcd6103d464d7b2fd2c5995bc170f0fb983
Deleted: sha256:1b619e485a6e6cff24ef70de0b0b85f93ecd84c742e01089a72a831e9137d349
Deleted: sha256:bad11f9d3c3b598170540702f700b88d9ed06798ef61c243afe5a80fe0b3627a
Deleted: sha256:3f2004e5d50164ae4a6e46fdebec079cb87d2b510e244842e234f4e92cf6bc9a
Untagged: goharbor/trivy-adapter-photon:v2.9.1
Deleted: sha256:a02695b8f8eac87d090572f866b2b9d5fc583d039e198edcae0510c66b340492
Deleted: sha256:6f66d86567499f8f7d1bad7212772ae57e3f010a682c80771123988f170ce9b3
Deleted: sha256:aec83a41abfad17df280b7840183ca3352a77b743e5285988fc06e7d58a504a0
Deleted: sha256:986df79b5430a2c679047a66c70809c89e6d92153f20c26446fb3abc8ab7b428
Deleted: sha256:fbc8798838d90086c1e4041fc68b5bead2201f7fe07a93122efc7b5c7a1da8a0
Deleted: sha256:eaed9c6ee96f720c8f335253c316e15973d487d729643d4383abd29ce9c1ac59
Deleted: sha256:5295d28bda80ed2132b81078f0535c4a913db100f4a1447d64b21cb5e94102e1
Untagged: goharbor/harbor-registryctl:v2.9.1
Deleted: sha256:a076218bb6317003a69ce3d8a60652da14a4f405063bff9c66592d1b38ae8c73
Deleted: sha256:0c6119bfe2e35c71786d8b21565af3095476d7475cd9bf70c689b32f3c28c87e
Deleted: sha256:dcc95dc1a6bc300021bbe38921b03af4e1a5a2816a1aacf0b4fdb67ab424f78d
Deleted: sha256:a4280f868c256a9cccfaeaac49d76d552e8b6f1f669878951dbdee8937cd1875
Deleted: sha256:55b22cad27947ee41cea44a1051b1481120056f344c0b374f1f59a098e3ea238
Deleted: sha256:f1a45c1f6b28d7cf3b6f97326691fe8c40e5af631cb218d70509ace87f3597d3
Deleted: sha256:1e84dbc46ed4e3af25a37dc07fab10edbdeab6ac465f66f92674b7bd9c695c5d
Untagged: goharbor/registry-photon:v2.9.1
Deleted: sha256:2f01ea8b1853dd95d5b4d0c94cda109344b486988d5b9ac4768d8070306f5510
Deleted: sha256:9a53e88be783f686257721e5c0883e6ebf879f3be5e20976b8b111b65491b08b
Deleted: sha256:6183eb32d8f7ffb82e11c4823a165ddb25603b06f0c9f0be576aa1ed6139f534
Deleted: sha256:f77184ca612e5349a75d8a231220b25cbb8b4fd511df83ed5e2f2ee7ba9564ca
Deleted: sha256:111fcfc4e06b697ac227342d2c550f06c1146be773acb9b21948074c18d86429
Deleted: sha256:6a97b0645f114eafe800920a52f945a1c60b4f9bbece2a790b4fd8c02a78c1c7
Untagged: goharbor/nginx-photon:v2.9.1
Deleted: sha256:5200203dd7ef0d2ae6368949492742a4abe18cbbef626373a37276214f4dfe5b
Deleted: sha256:d4f9435903e53d8d1d41aede68fd1a9238a5b750a1b84d0a3f5ef2e0d7f75021
Untagged: goharbor/harbor-log:v2.9.1
Deleted: sha256:ac1cdcc94a5f5cbff294080d0aa2e4fd31ffb8727855e086059e58ec81280739
Deleted: sha256:d43f5a4f4f3f5a382710d247559dd50471defc0aa57761b5a773064a585793e9
Deleted: sha256:df6b13fdffb18ed995bf78069a02e68915329ae3c6b764c0af04404d94814406
Deleted: sha256:8fe7f68a89d0200f285015c8d88be498ae721ce63e8a5af8224ffa894ac33da9
Deleted: sha256:8affbce0c0f8297c11793c0cd1b226297a70cb89d925866a156516fdb5319dd3
Deleted: sha256:41cfc52d0ea6fff96285430f934102d29c3c69f24dfc61586944564046fd7455
Deleted: sha256:3f1ec1f672aaccc2989643f0a5bef68b5048faddfdc1ce86d1a9ba1636a97da0
Deleted: sha256:2ec5830ab930f99e3c9ba49f814970f7141bf586e57553b7be216e246ddd3590
Untagged: goharbor/harbor-jobservice:v2.9.1
Deleted: sha256:d9ff6fc98cc8693d662a2a1849863d59f266701cd6d0eb716c6235464a55b8a3
Deleted: sha256:69e91434e21e698e77d42d01738037bba64ceb503c344bc780228f9aeac337a3
Deleted: sha256:5d02de6a7bcf07ba76646a39955e0a9d0213546c75a19cc21327d964199ab9a0
Deleted: sha256:863218333064edbc6edf222aeade2412bffa0d2a4b9cf6a013d34798903483ae
Deleted: sha256:0245594795af4737058bb2ab39f2002a521dda19d7b96763b61896e1ddf7fc58
Deleted: sha256:c4fc25d0d53c640b53fa2cb317b0e625accac292c21dbdb7a70e4f4712a51c2a
Untagged: goharbor/harbor-core:v2.9.1
Deleted: sha256:0a3a7953409c97d5de36a752aae79b6c7cb024cb3121cb53b7e685539eafb022
Deleted: sha256:842bd22596839a87fce06ccd356bb4b0259082ad3ee14e679bf07c98c15db00e
Deleted: sha256:8191a3866b3a71f92fd45475d491c1df411bff4895ae5b40c9f3ed68e778efde
Deleted: sha256:bda618c9cd487fb8bad242fc5e8b7a6f602f5a8d55dd1742dd25b9a6eb493989
Deleted: sha256:391255ee55fa66785f40545204cf15e1fe9452b1cbcac5b4a888bfacce27ad50
Deleted: sha256:7f330a0b9d000c6a72ec4d6e9ad7a3fd0934bd2a44e7804023d99e92d0fd7d0d
Deleted: sha256:b8b311fe17ec79c0a47c8925d3783bd498b7d4ce6309a91d67311db532e2bb7c
Deleted: sha256:992161c96a7cec9ddc1b73b50e229704d58ea1e0bf6dd7f024d11b9026b8b678
Deleted: sha256:bb6f2fe8a1daa4fc7dc387a7fc2084852e550fd691189953ec786b50c150ad65
Deleted: sha256:1d5d742cd2f205dbc818465933a929c5889926cea342eaf26786db1d8cbd1767
Untagged: goharbor/harbor-portal:v2.9.1
Deleted: sha256:345284db8ca1450a48907c001e9afa3ac5a9142f6883a5203917b1d1c2297c41
Deleted: sha256:178d8bf87f73372e971261b1d866f147ec91ddb5433fe56c5f28eb6ca2d5dbf5
Deleted: sha256:a8506ddb9657df7554b881722e242ff7a7fbf38a79cd5e98792c7ed5bda78161
Deleted: sha256:8bc8db00aacb5067a665f3ffacd9aa32544fbb4c0c6f2037d1e5f961f79c45a9
Deleted: sha256:353f676a6ba2263382050f090f143954fca2aab92e48f3008f9beb359e39c20d
Untagged: goharbor/harbor-db:v2.9.1
Deleted: sha256:69606d285be10ffcda72eef549fb09fe09674f30ddb5b2e454b187b96cc47f98
Deleted: sha256:6b95cf61dc4ca36384a4f88efc0344e6f4220aa0f20389bd5c663c2501b6277a
Deleted: sha256:40d28a464ce486fe8a6a499f3127f4a39f69299d05435c85da266c44bf8f427c
Deleted: sha256:1d16d9dc37e07c50bbe630580639500acf0d41e9a305d0481bba91f120e29a61
Deleted: sha256:1362637b7ed98159892c6dae26aa71f821d82713e36baea83839ae8c1aba9331
Deleted: sha256:34bba98c3867fce6cd5d5d7b82a0a2c8729d83c91bd2552327e6e626d9062ca9
Deleted: sha256:0ee0918d983bbeb0a10df2e34afd228fc490a9604cafc065645498cc96e5d964
Deleted: sha256:a49a0ffdba8ed297fe59f15f7e5613c597fc92960e3822ee160579bffce155d1
Deleted: sha256:34c04552a3bd04dfa1c011d4ee9ea990e7956bb69d83c27fbfadef91d3a26409
Deleted: sha256:a96f84f4bb004ee4c844b1cd9dc71c75bb5cae51a711efbc819e3f3fd49ea488
Deleted: sha256:3b080a100aa1bb78ddc33257687bf456bd8babba7fc1944798d46540b2603c34
Untagged: goharbor/prepare:v2.9.1
Deleted: sha256:adb2d804c4588f9340d38c22fb2ec12d54114e893443c14908380a1f8aecb1bd
Deleted: sha256:d1a6baf565caf9942c21bdb81b47eb74267eb96c322b3f01358c39105ee730c7
Deleted: sha256:5250ab926e7a446d55e76651c8d15c459db3e462899b6b09bf9cb8da707f8bb8
Deleted: sha256:8ed82533058d1dae715315227d2555d2139e116e6b9a749980b834d0b349f866
Deleted: sha256:9a995109826461f544be2c9c11ae901d43fc2c779e59775dfb77e90767a94dc0
Deleted: sha256:008d0b8cd09da506e791b383ad02a80538c527f387eff55b654466073637ba7f
Deleted: sha256:805eb49aaed7bded8f7fa8436f95682152323d764f31eaf98b7adc5cc6f876c6
Deleted: sha256:9482be7b67f1b43c21d86b19e8f0b37666fe7a0d48ee2c90f4188b9c8979f1fd
Deleted: sha256:9b8208529ab4fdfdca1fede2c76328941325c172df61467d228b0d08c3bdad15
Deleted: sha256:5442310fb69bd7cab1bcc9b349a351a0424d523c001409a929887ea2b468edd5
Deleted: sha256:a1dcbad8836c54246278629e71fd3849e01438a7fe27ac63d5c7af9855b027ef
[root@docker harbor 11:48:22]# rm -rf /data/
[root@docker harbor 11:48:35]# cd /opt
[root@docker opt 11:48:52]# cd
[root@docker ~ 11:48:59]# ls
'=' harbor-offline-installer-v2.9.1.tgz testfile
anaconda-ks.cfg httpd.dockerfile tmpfile2
CACHED index.html transferring
centos.ssh.dockerfile '[internal]' writing
Dockerfile myfile 'ystemctl restart docker'
exporting naming
harbor passwd.tar.gz
[root@docker ~ 11:49:01]# rm -rf harbor-offline-installer-v2.9.1.tgz
[root@docker ~ 11:49:16]# rm -rf /opt/harbor/
本地镜像文件导入本地(load)和删除本地镜像,导入本地镜像文件
[root@docker ~ 13:53:21]# docker save httpd -o httpd.tar
[root@docker ~ 13:55:11]# ls
'=' Dockerfile httpd.tar naming transferring
anaconda-ks.cfg exporting index.html passwd.tar.gz writing
CACHED harbor '[internal]' testfile 'ystemctl restart docker'
centos.ssh.dockerfile httpd.dockerfile myfile tmpfile2
[root@docker ~ 13:55:51]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centosjava8 461 1846f520e9a7 45 hours ago 537MB
httpd centos 1fd2344332e6 46 hours ago 253MB
swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd v1 1fd2344332e6 46 hours ago 253MB
centos ssh 29a83cb13ca9 46 hours ago 283MB
my-image latest 358f35e5adf2 2 days ago 4.42MB
image-debug latest d9f1f51394d4 2 days ago 4.42MB
xmy v2 d9f1f51394d4 2 days ago 4.42MB
vim-1-dockerfile-3 latest 9d071477d1b7 2 days ago 213MB
vim-1-dockerfile-2 latest bcc3d0fd9fb9 2 days ago 213MB
vim-1 latest 5e42e96ce759 2 days ago 213MB
vim latest 7a12be773edc 2 days ago 100MB
vim-1-dockerfile latest 5081df56d3d7 2 days ago 213MB
ubuntu-with-vim-dockerfile latest 5081df56d3d7 2 days ago 213MB
192.168.108.30/cloud/httpd latest 58d56e9057ae 5 days ago 117MB
httpd latest 58d56e9057ae 5 days ago 117MB
localhost:5000/httpd v1 58d56e9057ae 5 days ago 117MB
ubuntu latest 30ba44506a6d 2 weeks ago 100MB
dockerfile3 latest 41b72d7c2c45 19 months ago 4.42MB
centos.ssh.dockerfile latest 124ba07f6cf0 19 months ago 4.42MB
dockerfile7 latest 124ba07f6cf0 19 months ago 4.42MB
dockerfile1 latest c1b8220c6083 19 months ago 4.42MB
dockerfile2 latest 778b52143a69 19 months ago 4.42MB
dockerfile6 latest ca804453d33a 19 months ago 4.42MB
<none> <none> 72ac116e2bd9 19 months ago 4.42MB
dockerfile5 latest 9ff0c8a8f5a9 19 months ago 4.42MB
registry 2 26b2eb03618e 2 years ago 25.4MB
centos 7 eeb6ee3f44bd 4 years ago 204MB
[root@docker ~ 13:56:11]# docker rmi httpd:latest
Untagged: httpd:latest
Untagged: httpd@sha256:86f9f50b96b32fe271b3650bbf9a1b71ac501b60d1554b109a08cec2443a47d2
[root@docker ~ 13:56:34]# docker images.tar
docker: 'images.tar' is not a docker command.
See 'docker --help'
[root@docker ~ 13:56:52]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centosjava8 461 1846f520e9a7 45 hours ago 537MB
httpd centos 1fd2344332e6 46 hours ago 253MB
swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd v1 1fd2344332e6 46 hours ago 253MB
centos ssh 29a83cb13ca9 46 hours ago 283MB
my-image latest 358f35e5adf2 2 days ago 4.42MB
image-debug latest d9f1f51394d4 2 days ago 4.42MB
xmy v2 d9f1f51394d4 2 days ago 4.42MB
vim-1-dockerfile-3 latest 9d071477d1b7 2 days ago 213MB
vim-1-dockerfile-2 latest bcc3d0fd9fb9 2 days ago 213MB
vim-1 latest 5e42e96ce759 2 days ago 213MB
vim latest 7a12be773edc 2 days ago 100MB
ubuntu-with-vim-dockerfile latest 5081df56d3d7 2 days ago 213MB
vim-1-dockerfile latest 5081df56d3d7 2 days ago 213MB
192.168.108.30/cloud/httpd latest 58d56e9057ae 5 days ago 117MB
localhost:5000/httpd v1 58d56e9057ae 5 days ago 117MB
ubuntu latest 30ba44506a6d 2 weeks ago 100MB
centos.ssh.dockerfile latest 124ba07f6cf0 19 months ago 4.42MB
dockerfile7 latest 124ba07f6cf0 19 months ago 4.42MB
dockerfile1 latest c1b8220c6083 19 months ago 4.42MB
dockerfile3 latest 41b72d7c2c45 19 months ago 4.42MB
<none> <none> 72ac116e2bd9 19 months ago 4.42MB
dockerfile2 latest 778b52143a69 19 months ago 4.42MB
dockerfile5 latest 9ff0c8a8f5a9 19 months ago 4.42MB
dockerfile6 latest ca804453d33a 19 months ago 4.42MB
registry 2 26b2eb03618e 2 years ago 25.4MB
centos 7 eeb6ee3f44bd 4 years ago 204MB
[root@docker ~ 13:57:05]# docker load -i images.tar
open images.tar: no such file or directory
[root@docker ~ 13:57:23]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centosjava8 461 1846f520e9a7 45 hours ago 537MB
httpd centos 1fd2344332e6 46 hours ago 253MB
swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd v1 1fd2344332e6 46 hours ago 253MB
centos ssh 29a83cb13ca9 46 hours ago 283MB
my-image latest 358f35e5adf2 2 days ago 4.42MB
image-debug latest d9f1f51394d4 2 days ago 4.42MB
xmy v2 d9f1f51394d4 2 days ago 4.42MB
vim-1-dockerfile-3 latest 9d071477d1b7 2 days ago 213MB
vim-1-dockerfile-2 latest bcc3d0fd9fb9 2 days ago 213MB
vim-1 latest 5e42e96ce759 2 days ago 213MB
vim latest 7a12be773edc 2 days ago 100MB
ubuntu-with-vim-dockerfile latest 5081df56d3d7 2 days ago 213MB
vim-1-dockerfile latest 5081df56d3d7 2 days ago 213MB
192.168.108.30/cloud/httpd latest 58d56e9057ae 5 days ago 117MB
localhost:5000/httpd v1 58d56e9057ae 5 days ago 117MB
ubuntu latest 30ba44506a6d 2 weeks ago 100MB
<none> <none> 72ac116e2bd9 19 months ago 4.42MB
centos.ssh.dockerfile latest 124ba07f6cf0 19 months ago 4.42MB
dockerfile7 latest 124ba07f6cf0 19 months ago 4.42MB
dockerfile3 latest 41b72d7c2c45 19 months ago 4.42MB
dockerfile6 latest ca804453d33a 19 months ago 4.42MB
dockerfile1 latest c1b8220c6083 19 months ago 4.42MB
dockerfile2 latest 778b52143a69 19 months ago 4.42MB
dockerfile5 latest 9ff0c8a8f5a9 19 months ago 4.42MB
registry 2 26b2eb03618e 2 years ago 25.4MB
centos 7 eeb6ee3f44bd 4 years ago 204MB
[root@docker ~ 13:57:40]# docker rm -f $(docker ps-aq)
docker: 'ps-aq' is not a docker command.
See 'docker --help'
"docker rm" requires at least 1 argument.
See 'docker rm --help'.
Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]
Remove one or more containers
[root@docker ~ 13:58:13]# docker rm -f $(docker ps -aq)
71c954ccfabb
96297bbe8443
32f58576da4d
3c8fd49b13cb
8a9dbf2cc3af
64e8868128d9
588d4e97be2d
c085ec41b22a
4e1c72bbcbea
4431a54aad63
509e1302235d
7126dbbc6d92
eac13b2f2507
80bf9448e6df
33157c8f5444
e0bf2cc1d3b4
80c8ed1e9658
ade6af32786c
8be94e026124
80f2592218d0
c3f62a6ca1be
d7d8cd067b6a
cb172eb26622
9feb4cba0340
87405dc65d62
55734c361c0a
[root@docker ~ 13:58:32]# docker rmi -f $(docker images -aq)
Untagged: centosjava8:461
Deleted: sha256:1846f520e9a7ec088adae3c389b13a23ba839b1d42b083b57e3a184096d05275
Untagged: httpd:centos
Untagged: swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd:v1
Untagged: swr.cn-east-3.myhuaweicloud.com/mymy/centos_httpd@sha256:1a5a7e17f84f74ea066ddb15fd4e13a7eb70169d27d0e15da8891ec27988cb3c
Deleted: sha256:1fd2344332e685a12eacb4a42bb23c32dd30af565c296e2b41e37dae55ca38b4
Untagged: centos:ssh
Deleted: sha256:29a83cb13ca956e0117a534d67cdf1bbf21fa2825e7e666dcd2963702b905229
Untagged: my-image:latest
Deleted: sha256:358f35e5adf21eb7cda0d04341579856c08519b020f92d936bc599f699469993
Untagged: image-debug:latest
Untagged: xmy:v2
Deleted: sha256:d9f1f51394d47fac13834c5a5cdb1dd2183050db635dae3abb2fa047fb28ab98
Untagged: vim-1-dockerfile-3:latest
Deleted: sha256:9d071477d1b7dc4e124a13406517ea88df8fbe8a0d48a6e8c283cc09aa630d13
Untagged: vim-1-dockerfile-2:latest
Deleted: sha256:bcc3d0fd9fb9770ee2240838425ebcebb60a881349f47d0f26ba12e64b62e403
Untagged: vim-1:latest
Deleted: sha256:5e42e96ce759ca21003e4fe780583573b37e949d72e7e5ec22b9a4834f212dd3
Deleted: sha256:84a5edb6918a9c58c7df6cdc47a6348dcd86be211056539de7677da6bbf308ea
Untagged: vim:latest
Deleted: sha256:7a12be773edc98bf4692f3b5c6b2f976f5b89a84e995f09b800c1bc3fc67ecaf
Untagged: ubuntu-with-vim-dockerfile:latest
Untagged: vim-1-dockerfile:latest
Deleted: sha256:5081df56d3d76a6e063fff2f0b0379646e867eeee3314ff3c5a324f82b9b65de
Untagged: 192.168.108.30/cloud/httpd:latest
Untagged: 192.168.108.30/cloud/httpd@sha256:d505d46934d1727c62b78cf5e52d363fd26171c4dc465d9f566dcc7c79f03147
Untagged: localhost:5000/httpd:v1
Untagged: localhost:5000/httpd@sha256:d505d46934d1727c62b78cf5e52d363fd26171c4dc465d9f566dcc7c79f03147
Deleted: sha256:58d56e9057aec2419da9786593e9150e975a991919abf19b61d7dbb82af53cdd
Deleted: sha256:1ce41626f41049129d6f80d03739d3b6f43e24ad28d90a7a25b9bb0d8bab75e9
Deleted: sha256:f5fbb3d1c1308b4bb0181645444913aff73ec127bded54e61db5ebc2d99cc28c
Deleted: sha256:3fc3b90baade0554bd7084e2a97f89d885afdb4467fd4b31d7510198fb0b3e7a
Deleted: sha256:a4183746320f4f7df6fd2a1d9131c8b7d61788b9120a12bb767758604f15df21
Deleted: sha256:417cfd81767b5689f3c2e2a562b14536eaf2608ba71253cd4e26b535ad2f011f
Deleted: sha256:6d7c150df58d41c351cd9b03f1cda7a9a23d6fc91436e2bf0f098c6dd78c9c55
Untagged: ubuntu:latest
Untagged: ubuntu@sha256:f3d28607ddd78734bb7f71f117f3c6706c666b8b76cbff7c9ff6e5718d46ff64
Deleted: sha256:30ba44506a6d003153c80023c4474e67d3487e9178df254bde55b19209cc8683
Deleted: sha256:72ac116e2bd9f49b6eac15bec4aa3c1cc8916a779a1987c456249b192678eac0
Untagged: centos.ssh.dockerfile:latest
Untagged: dockerfile7:latest
Deleted: sha256:124ba07f6cf01f8c1e60c32c23b47b9916de459db074755ff55260be2984e075
Untagged: dockerfile6:latest
Deleted: sha256:ca804453d33a65bad561de32b81d0a9dee109ec6505fb3d401b848368c387a59
Untagged: dockerfile1:latest
Deleted: sha256:c1b8220c6083bb17b61ed1548f090e7f54e6a955ea431608e3121c46be34d8dd
Untagged: dockerfile5:latest
Deleted: sha256:9ff0c8a8f5a95f520c7f69fa58f3f8fa2f8ba7aef082202516a17fd106441872
Untagged: dockerfile3:latest
Deleted: sha256:41b72d7c2c4581c389898d0e7da9999b331b7fb998c159f7d10e075428e072c8
Untagged: dockerfile2:latest
Deleted: sha256:778b52143a6972f51ffa3c3700148d5adef6f9a261a616134c7c57e2ea6f021d
Untagged: registry:2
Untagged: registry@sha256:a3d8aaa63ed8681a604f1dea0aa03f100d5895b6a58ace528858a7b332415373
Deleted: sha256:26b2eb03618e749084668eaff68cff8f81dda12d06ac641be7a6398b82a6f25b
Deleted: sha256:d0d58372b64cbe0bd8c1300a76f4a2a29ceac9c24878064778170f3cc6b6958c
Deleted: sha256:ad7b5fa2063c245cce8b9b07820829f1c394651e3b73b6966866f2dacf36bdda
Deleted: sha256:78eca7e96340d3410d2e4292098c1e496976add50025c9a6e6e45617397cb19c
Deleted: sha256:d0983639fe984f22d91f298ea9594c0fffe62210427db91fa891b83b92dd6b84
Deleted: sha256:f44f286046d9443b2aeb895c0e1f4e688698247427bca4d15112c8e3432a803e
Untagged: centos:7
Untagged: centos@sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4
Deleted: sha256:eeb6ee3f44bd0b5103bb561b4c16bcb82328cfe5809ab675bb17ab3a16c517c9
Deleted: sha256:174f5685490326fc0a1c0f5570b8663732189b327007e47ff13d2ca59673db02
Error response from daemon: No such image: 1fd2344332e6:latest
Error response from daemon: No such image: d9f1f51394d4:latest
Error response from daemon: No such image: 5081df56d3d7:latest
Error response from daemon: No such image: 58d56e9057ae:latest
Error response from daemon: No such image: 124ba07f6cf0:latest
[root@docker ~ 13:58:56]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
容器
如何运行容器
[root@docker ~ 13:59:09]# docker create ubuntu
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
6f5c5aa4e145: Already exists
1c24335ddd46: Already exists
Digest: sha256:f3d28607ddd78734bb7f71f117f3c6706c666b8b76cbff7c9ff6e5718d46ff64
Status: Downloaded newer image for ubuntu:latest
8d46c14cff84279f249eef53210d26d0b45047c13b1e483f9589fab139685bb0
[root@docker ~ 14:27:58]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8d46c14cff84 ubuntu "/bin/bash" 8 seconds ago Created angry_hofstadter
[root@docker ~ 14:28:06]# docker start 8d46c14cff84
8d46c14cff84
[root@docker ~ 14:28:59]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8d46c14cff84 ubuntu "/bin/bash" About a minute ago Exited (0) 7 seconds ago angry_hofstadter
[root@docker ~ 14:29:56]# docker run ubuntu pwd
/
[root@docker ~ 14:30:04]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@docker ~ 14:31:40]# docker run -d ubuntu /bin/bash -c "while true ;do sleep 1 ;echo xuewu;done"
8682b1aa395c95b939ab2d81fa86939e2b8020971d69a7408c367a6e629e1ecc
[root@docker ~ 14:31:49]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8682b1aa395c ubuntu "/bin/bash -c 'while…" 17 seconds ago Up 16 seconds sharp_davinci
[root@docker ~ 14:32:05]# docker stop 8682b1aa395c
8682b1aa395c
进入容器方法
docker attach
[root@docker ~]# docker run -d ubuntu /bin/bash -c "while true ; do sleep 1 ;
echo I_am_in_container ; done"
dc508b94447f83b46080267580607569a187fcc7f780433f646e9d66949731a6
[root@docker ~]#
[root@docker ~]# docker attach
dc508b94447f83b46080267580607569a187fcc7f780433f646e9d66949731a6
I_am_in_container
I_am_in_container
I_am_in_container
I_am_in_container
docker exec
[root@docker ~ 15:00:31]# docker exec -it ff42b9c2b7c7d
"docker exec" requires at least 2 arguments.
See 'docker exec --help'.
Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Execute a command in a running container
[root@docker ~ 15:01:06]# docker exec -it ff42b9c2b7c7d bash
root@ff42b9c2b7c7:/# ps -elf
F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD
4 S root 1 0 0 80 0 - 1126 - 06:58 ? 00:00:00 /bin/bash -c while true
4 S root 201 0 0 80 0 - 1192 - 07:01 pts/0 00:00:00 bash
0 S root 222 1 0 80 0 - 4026 hrtime 07:01 ? 00:00:00 sleep 1
4 R root 223 201 0 80 0 - 1700 - 07:01 pts/0 00:00:00 ps -elf
root@ff42b9c2b7c7:/# exit
exit
[root@docker ~ 15:01:39]# docker logs -f ff42b9c2b7c7d
I_am_in_container
I_am_in_container
024运行容器的最佳实践
[root@docker ~ 15:03:49]# docker run -it busybox
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
481282afbc43: Already exists
Digest: sha256:1487d0af5f52b4ba31c7e465126ee2123fe3f2305d638e7827681e7cf6c83d5e
Status: Downloaded newer image for busybox:latest
/ # wget www.baidu.com
Connecting to www.baidu.com (180.101.49.44:80)
saving to 'index.html'
index.html 100% |******************************************************| 2381 0:00:00 ETA
'index.html' saved
/ # exit
025 容器常用操作
前面讨论了如何运行容器,本节学习容器的其他常用操作。
stop/start/restart 容器
通过 docker stop 可以停止运行的容器。
[root@docker ~ 15:24:33]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ff42b9c2b7c7 ubuntu "/bin/bash -c 'while…" 26 minutes ago Up 26 minutes brave_nightingale
[root@docker ~ 15:24:46]# docker stop vigorous_pike
Error response from daemon: No such container: vigorous_pike
[root@docker ~ 15:25:00]# docker stop brave_nightingale
brave_nightingale
[root@docker ~ 15:26:01]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
363bb5b36840 busybox "sh" 2 minutes ago Exited (0) About a minute ago angry_chatelet
ff42b9c2b7c7 ubuntu "/bin/bash -c 'while…" 28 minutes ago Exited (137) 7 seconds ago brave_nightingale
8682b1aa395c ubuntu "/bin/bash -c 'while…" 54 minutes ago Exited (137) 53 minutes ago sharp_davinci
3f0f8f240d17 ubuntu "pwd" 56 minutes ago Exited (0) 56 minutes ago exciting_morse
8d46c14cff84 ubuntu "/bin/bash" 58 minutes ago Exited (0) 57 minutes ago angry_hofstadter
[root@docker ~ 15:28:15]# docker start angry_chatelet
angry_chatelet
[root@docker ~ 15:28:30]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
363bb5b36840 busybox "sh" 4 minutes ago Up 7 seconds angry_chatelet
[root@docker ~ 15:28:37]# docker run -d --restart=always httpd
Unable to find image 'httpd:latest' locally
latest: Pulling from library/httpd
57fb71246055: Pull complete
4b31e7d9a3b8: Pull complete
4f4fb700ef54: Pull complete
6e3e6d1d5b56: Pull complete
777279f5ce9f: Pull complete
4b705a141cea: Pull complete
Digest: sha256:bac8021a9b7ad41a399dc72bb0e1f0b832b565632df7e62871e07d2aca8b293e
Status: Downloaded newer image for httpd:latest
b0141c9ee7e956e4aaf70246dafe11e4a909e36edb7c17d51c4d6575a4b3f8aa
[root@docker ~ 15:29:15]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b0141c9ee7e9 httpd "httpd-foreground" 15 seconds ago Up 14 seconds 80/tcp adoring_chebyshev
363bb5b36840 busybox "sh" 5 minutes ago Up 59 seconds angry_chatelet
[root@docker ~ 15:29:29]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b0141c9ee7e9 httpd "httpd-foreground" 29 seconds ago Up 27 seconds 80/tcp adoring_chebyshev
363bb5b36840 busybox "sh" 5 minutes ago Up About a minute angry_chatelet
[root@docker ~ 15:29:43]# docker pause angry_chatelet
angry_chatelet
[root@docker ~ 15:29:58]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b0141c9ee7e9 httpd "httpd-foreground" 53 seconds ago Up 52 seconds 80/tcp adoring_chebyshev
363bb5b36840 busybox "sh" 6 minutes ago Up About a minute (Paused) angry_chatelet
[root@docker ~ 15:30:07]# docker unpause angry_chatelet
angry_chatelet
[root@docker ~ 15:30:42]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b0141c9ee7e9 httpd "httpd-foreground" About a minute ago Up About a minute 80/tcp adoring_chebyshev
363bb5b36840 busybox "sh" 6 minutes ago Up 2 minutes angry_chatelet
[root@docker ~ 15:31:20]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b0141c9ee7e9 httpd "httpd-foreground" 2 minutes ago Up 2 minutes 80/tcp adoring_chebyshev
363bb5b36840 busybox "sh" 7 minutes ago Up 2 minutes angry_chatelet
ff42b9c2b7c7 ubuntu "/bin/bash -c 'while…" 33 minutes ago Exited (137) 5 minutes ago brave_nightingale
8682b1aa395c ubuntu "/bin/bash -c 'while…" 59 minutes ago Exited (137) 58 minutes ago sharp_davinci
3f0f8f240d17 ubuntu "pwd" About an hour ago Exited (0) About an hour ago exciting_morse
8d46c14cff84 ubuntu "/bin/bash" About an hour ago Exited (0) About an hour ago angry_hofstadter
[root@docker ~ 15:31:22]# docker rm 8682b1aa395c ff42b9c2b7c7
8682b1aa395c
ff42b9c2b7c7
[root@docker ~ 15:32:07]#
026一张图搞懂容器所有操作
[root@docker ~ 15:32:07]# docker create httpd
80c5fcbbe49d99a0271ced060636b221612b64088304a9d641f32a9250649eda
[root@docker ~ 15:54:40]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
80c5fcbbe49d httpd "httpd-foreground" 8 seconds ago Created priceless_northcutt
b0141c9ee7e9 httpd "httpd-foreground" 25 minutes ago Up 25 minutes 80/tcp adoring_chebyshev
363bb5b36840 busybox "sh" 30 minutes ago Up 26 minutes angry_chatelet
3f0f8f240d17 ubuntu "pwd" About an hour ago Exited (0) About an hour ago exciting_morse
8d46c14cff84 ubuntu "/bin/bash" About an hour ago Exited (0) About an hour ago angry_hofstadter
[root@docker ~ 15:54:48]# docker start 80
80
[root@docker ~ 15:55:34]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
80c5fcbbe49d httpd "httpd-foreground" About a minute ago Up 20 seconds 80/tcp priceless_northcutt
b0141c9ee7e9 httpd "httpd-foreground" 26 minutes ago Up 26 minutes 80/tcp adoring_chebyshev
363bb5b36840 busybox "sh" 31 minutes ago Up 27 minutes angry_chatelet
[root@docker ~ 15:56:52]# docker run -d --restart=always --name httpd11 httpd
64789f64bfbb94335cbe19847db198ad685a3a995e8a05a3a539fc9b75a7dbca
[root@docker ~ 15:57:04]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
64789f64bfbb httpd "httpd-foreground" 9 seconds ago Up 7 seconds 80/tcp httpd11
80c5fcbbe49d httpd "httpd-foreground" 2 minutes ago Up About a minute 80/tcp priceless_northcutt
b0141c9ee7e9 httpd "httpd-foreground" 27 minutes ago Up 27 minutes 80/tcp adoring_chebyshev
363bb5b36840 busybox "sh" 33 minutes ago Up 28 minutes angry_chatelet
[root@docker ~ 15:57:07]# docker attach httpd11
^C[Mon May 11 07:58:34.763850 2026] [mpm_event:notice] [pid 1:tid 1] AH00491: caught SIGTERM, shutting down
[root@docker ~ 15:58:34]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
64789f64bfbb httpd "httpd-foreground" About a minute ago Up 10 seconds 80/tcp httpd11
80c5fcbbe49d httpd "httpd-foreground" 4 minutes ago Up 3 minutes 80/tcp priceless_northcutt
b0141c9ee7e9 httpd "httpd-foreground" 29 minutes ago Up 29 minutes 80/tcp adoring_chebyshev
363bb5b36840 busybox "sh" 34 minutes ago Up 30 minutes angry_chatelet
3f0f8f240d17 ubuntu "pwd" About an hour ago Exited (0) About an hour ago exciting_morse
8d46c14cff84 ubuntu "/bin/bash" 2 hours ago Exited (0) About an hour ago angry_hofstadter
[root@docker ~ 15:58:45]# docker stop httpd11
httpd11
[root@docker ~ 15:59:02]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
64789f64bfbb httpd "httpd-foreground" 2 minutes ago Exited (0) 8 seconds ago httpd11
80c5fcbbe49d httpd "httpd-foreground" 4 minutes ago Up 3 minutes 80/tcp priceless_northcutt
b0141c9ee7e9 httpd "httpd-foreground" 29 minutes ago Up 29 minutes 80/tcp adoring_chebyshev
363bb5b36840 busybox "sh" 35 minutes ago Up 30 minutes angry_chatelet
3f0f8f240d17 ubuntu "pwd" About an hour ago Exited (0) About an hour ago exciting_morse
8d46c14cff84 ubuntu "/bin/bash" 2 hours ago Exited (0) 2 hours ago angry_hofstadter
029容器对内存限制
[root@docker ~ 16:26:42]# vim Dockerfile
[root@docker ~ 16:27:14]# docker build -t ubuntu-with-stress . [+] Building 0.0s (6/6) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 156B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:latest 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [1/2] FROM docker.io/library/ubuntu:latest 0.0s
=> CACHED [2/2] RUN apt-get -y update && apt-get -y install stress 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:e25629a3bda3fca69afbef2e0fbe84dbb4d28c5163703db85973a5dbd8368dbd 0.0s
=> => naming to docker.io/library/ubuntu-with-stress 0.0s
[root@docker ~ 16:27:22]# docker run -it -m 200M --memory-swap=300M ubuntu-with-stress --vm 1 --vm-bytes 280M -v
stress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd
stress: dbug: [1] using backoff sleep of 3000us
stress: dbug: [1] --> hogvm worker 1 [7] forked
stress: dbug: [7] allocating 293601280 bytes ...
stress: dbug: [7] touching bytes in strides of 4096 bytes ...
stress: dbug: [7] freed 293601280 bytes
stress: dbug: [7] allocating 293601280 bytes ...
stress: dbug: [7] touching bytes in strides of 4096 bytes ...
stress: dbug: [7] freed 293601280 bytes
stress: dbug: [7] allocating 293601280 bytes ...
stress: dbug: [7] touching bytes in strides of 4096 bytes ...
stress: dbug: [7] freed 293601280 bytes
stress: dbug: [7] allocating 293601280 bytes ...
stress: dbug: [7] touching bytes in strides of 4096 bytes ...
stress: dbug: [7] freed 293601280 bytes
stress: dbug: [7] allocating 293601280 bytes ...
stress: dbug: [7] touching bytes in strides of 4096 bytes ...
stress: dbug: [7] freed 293601280 bytes
stress: dbug: [7] allocating 293601280 bytes ...
stress: dbug: [7] touching bytes in strides of 4096 bytes ...
stress: dbug: [7] freed 293601280 bytes
stress: dbug: [7] allocating 293601280 bytes ...
stress: dbug: [7] touching bytes in strides of 4096 bytes ...
stress: dbug: [7] freed 293601280 bytes
stress: dbug: [7] allocating 293601280 bytes ...
stress: dbug: [7] touching bytes in strides of 4096 bytes ...
stress: dbug: [7] freed 293601280 bytes
stress: dbug: [7] allocating 293601280 bytes ...
stress: dbug: [7] touching bytes in strides of 4096 bytes ...
stress: dbug: [7] freed 293601280 bytes
stress: dbug: [7] allocating 293601280 bytes ...
stress: dbug: [7] touching bytes in strides of 4096 bytes ...
^Cstress: FAIL: [1] (425) <-- worker 7 got signal 2
stress: WARN: [1] (427) now reaping child worker processes
stress: FAIL: [1] (431) kill error: No such process
stress: FAIL: [1] (461) failed run completed in 21s
[root@docker ~ 16:28:00]# docker build -t ubuntu-with-stress .
[+] Building 0.0s (6/6) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 156B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:latest 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [1/2] FROM docker.io/library/ubuntu:latest 0.0s
=> CACHED [2/2] RUN apt-get -y update && apt-get -y install stress 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:e25629a3bda3fca69afbef2e0fbe84dbb4d28c5163703db85973a5dbd8368dbd 0.0s
=> => naming to docker.io/library/ubuntu-with-stress 0.0s
[root@docker ~ 16:28:20]# docker run -it -m 200M --memory-swap=300M ubuntu-with-stress --vm 1 --vm-bytes 310M -v
stress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd
stress: dbug: [1] using backoff sleep of 3000us
stress: dbug: [1] --> hogvm worker 1 [7] forked
stress: dbug: [7] allocating 325058560 bytes ...
stress: dbug: [7] touching bytes in strides of 4096 bytes ...
stress: FAIL: [1] (425) <-- worker 7 got signal 9
stress: WARN: [1] (427) now reaping child worker processes
stress: FAIL: [1] (431) kill error: No such process
stress: FAIL: [1] (461) failed run completed in 0s
Dockerfile
#version 1
from ubuntu
maintainer my
run apt-get -y update && apt-get -y install stress
entrypoint ["/usr/bin/stress"]
030容器对CPU限制
窗口1
[root@docker ~ 16:56:21]# docker run --name "container_A" -it -c 1024 ubuntu-with-stress --cpu 1 -v
stress: info: [1] dispatching hogs: 1 cpu, 0 io, 0 vm, 0 hdd
stress: dbug: [1] using backoff sleep of 3000us
stress: dbug: [1] --> hogcpu worker 1 [7] forked
窗口2
[root@docker ~ 16:58:05]# docker ps --no-trunc
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1fa168aaaf0a4139144adae110d0eed2bebab046bdb6c9282c97d6823a0d2f6c ubuntu-with-stress "/usr/bin/stress --cpu 1 -v" About a minute ago Up About a minute container_A
80c5fcbbe49d99a0271ced060636b221612b64088304a9d641f32a9250649eda httpd "httpd-foreground" About an hour ago Up About an hour 80/tcp priceless_northcutt
b0141c9ee7e956e4aaf70246dafe11e4a909e36edb7c17d51c4d6575a4b3f8aa httpd "httpd-foreground" 2 hours ago Up 2 hours 80/tcp adoring_chebyshev
363bb5b36840164d20947e6f7217c10a85b2eeb9628d10233b9657d2b88439c8 busybox "sh" 2 hours ago Up 2 hours angry_chatelet
[root@docker ~ 16:59:22]# cat /sys/fs/cgroup/cpu/docker/1fa168aaaf0a/cpu.shares
cat: /sys/fs/cgroup/cpu/docker/1fa168aaaf0a/cpu.shares: No such file or directory
[root@docker ~ 17:00:49]# docker ps -aq --no-trunc
1fa168aaaf0a4139144adae110d0eed2bebab046bdb6c9282c97d6823a0d2f6c
d3508421c70b7f9d094ee0c70a65e623323bc2e68de0f832993f8d8deaff1d86
d29cb382f3bb24e217a964a6cd3c48446b0e63afa8676d04bf6ac6995fb9ff4b
df338c7e71e64896342be6f668d85c4be566a6acd5490c8ea27028c284f83730
80d9ca8db271aeec553cc8946e75d14c13189c6dc85296f57e46a35be09b1150
64789f64bfbb94335cbe19847db198ad685a3a995e8a05a3a539fc9b75a7dbca
80c5fcbbe49d99a0271ced060636b221612b64088304a9d641f32a9250649eda
b0141c9ee7e956e4aaf70246dafe11e4a909e36edb7c17d51c4d6575a4b3f8aa
363bb5b36840164d20947e6f7217c10a85b2eeb9628d10233b9657d2b88439c8
3f0f8f240d178480d87eb08f87e30e6c331d929d6b6690af443d034e0fdb3e85
8d46c14cff84279f249eef53210d26d0b45047c13b1e483f9589fab139685bb0
[root@docker ~ 17:01:26]# cat /sys/fs/cgroup/cpu/docker/1fa168aaaf0a4139144adae110d0eed2bebab046bdb6c9282c97d6823a0d2f6c/cpu.shares
1024
[root@docker ~ 17:01:57]# docker ps --no-trunc
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d865bdf33f880851cc486477325ad3a5217fcd8e189660fa4b649f6d0bd948aa ubuntu-with-stress "/usr/bin/stress --cpu 1 -v" 30 seconds ago Up 29 seconds container_C
1fa168aaaf0a4139144adae110d0eed2bebab046bdb6c9282c97d6823a0d2f6c ubuntu-with-stress "/usr/bin/stress --cpu 1 -v" 7 minutes ago Up 7 minutes container_A
80c5fcbbe49d99a0271ced060636b221612b64088304a9d641f32a9250649eda httpd "httpd-foreground" About an hour ago Up About an hour 80/tcp priceless_northcutt
b0141c9ee7e956e4aaf70246dafe11e4a909e36edb7c17d51c4d6575a4b3f8aa httpd "httpd-foreground" 2 hours ago Up 2 hours 80/tcp adoring_chebyshev
363bb5b36840164d20947e6f7217c10a85b2eeb9628d10233b9657d2b88439c8 busybox "sh" 2 hours ago Up 2 hours angry_chatelet
[root@docker ~ 17:05:06]# cat /sys/fs/cgroup/cpu/docker/d865bdf33f880851cc486477325ad3a5217fcd8e189660fa4b649f6d0bd948aa/cpu.shares
512
[root@docker ~ 17:06:14]# docker pause container_A
container_A
窗口3
[root@docker ~ 17:02:28]# docker run --name "container_B" -it -c 512 ubuntu-with-stress --cpu1 -v
stress: FAIL: [1] (251) unrecognized option: --cpu1
[root@docker ~ 17:03:22]# docker run --name "container_B" -it -c 512 ubuntu-with-stress --cpu 1 -v
docker: Error response from daemon: Conflict. The container name "/container_B" is already in use by container "b153e10ccc11e549d0530e595ec0032868f03ce1add5840c2417df4efe410a2b". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
[root@docker ~ 17:03:35]# docker run --name "container_C" -it -c 512 ubuntu-with-stress --cpu 1 -v
stress: info: [1] dispatching hogs: 1 cpu, 0 io, 0 vm, 0 hdd
stress: dbug: [1] using backoff sleep of 3000us
stress: dbug: [1] --> hogcpu worker 1 [7] forked
窗口4
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
d865bdf33f88 container_C 31.99% 1.188MiB / 3.548GiB 0.03% 866B / 0B 0B / 0B 2
1fa168aaaf0a container_A 64.38% 1.18MiB / 3.548GiB 0.03% 1.01kB / 0B 0B / 0B 2
80c5fcbbe49d priceless_northcutt 0.00% 18.89MiB / 3.548GiB 0.52% 1.38kB / 0B 0B / 0B 82
b0141c9ee7e9 adoring_chebyshev 0.01% 12.96MiB / 3.548GiB 0.36% 1.38kB / 0B 0B / 0B 82
363bb5b36840 angry_chatelet 0.00% 1.086MiB / 3.548GiB 0.03% 1.6kB / 0B 0B / 0B 1
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
d865bdf33f88 container_C 31.64% 1.188MiB / 3.548GiB 0.03% 866B / 0B 0B / 0B 2
1fa168aaaf0a container_A 62.97% 1.18MiB / 3.548GiB 0.03% 1.01kB / 0B 0B / 0B 2
80c5fcbbe49d priceless_northcutt 0.00% 18.89MiB / 3.548GiB 0.52% 1.38kB / 0B 0B / 0B 82
b0141c9ee7e9 adoring_chebyshev 0.00% 12.96MiB / 3.548GiB 0.36% 1.38kB / 0B 0B / 0B 82
363bb5b36840 angry_chatelet 0.00% 1.086MiB / 3.548GiB 0.03% 1.6kB / 0B 0B / 0B 1
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
d865bdf33f88 container_C 31.64% 1.188MiB / 3.548GiB 0.03% 866B / 0B 0B / 0B 2
1fa168aaaf0a container_A 62.97% 1.18MiB / 3.548GiB 0.03% 1.01kB / 0B 0B / 0B 2
80c5fcbbe49d priceless_northcutt 0.00% 18.89MiB / 3.548GiB 0.52% 1.38kB / 0B 0B / 0B 82
b0141c9ee7e9 adoring_chebyshev 0.00% 12.96MiB / 3.548GiB 0.36% 1.38kB / 0B 0B / 0B 82
363bb5b36840 angry_chatelet 0.00% 1.086MiB / 3.548GiB 0.03% 1.6kB / 0B 0B / 0B 1
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
d865bdf33f88 container_C 30.77% 1.188MiB / 3.548GiB 0.03% 866B / 0B 0B / 0B 2
1fa168aaaf0a container_A 62.97% 1.18MiB / 3.548GiB 0.03% 1.01kB / 0B 0B / 0B 2
80c5fcbbe49d priceless_northcutt 0.00% 18.89MiB / 3.548GiB 0.52% 1.38kB / 0B 0B / 0B 82
b0141c9ee7e9 adoring_chebyshev 0.00% 12.96MiB / 3.548GiB 0.36% 1.38kB / 0B 0B / 0B 82
363bb5b36840 angry_chatelet 0.00% 1.086MiB / 3.548GiB 0.03% 1.6kB / 0B 0B / 0B 1
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
d865bdf33f88 container_C 30.77% 1.188MiB / 3.548GiB 0.03% 866B / 0B 0B / 0B 2
1fa168aaaf0a container_A 59.91% 1.18MiB / 3.548GiB 0.03% 1.01kB / 0B 0B / 0B 2
80c5fcbbe49d priceless_northcutt 0.00% 18.89MiB / 3.548GiB 0.52% 1.38kB / 0B 0B / 0B 82
b0141c9ee7e9 adoring_chebyshev 0.00% 12.96MiB / 3.548GiB 0.36% 1.38kB / 0B 0B / 0B 82
363bb5b36840 angry_chatelet 0.00% 1.086MiB / 3.548GiB 0.03% 1.6kB / 0B 0B / 0B 1
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
d865bdf33f88 container_C 30.77% 1.188MiB / 3.548GiB 0.03% 866B / 0B 0B / 0B 2
1fa168aaaf0a container_A 59.91% 1.18MiB / 3.548GiB 0.03% 1.01kB / 0B 0B / 0B 2
80c5fcbbe49d priceless_northcutt 0.00% 18.89MiB / 3.548GiB 0.52% 1.38kB / 0B 0B / 0B 82
b0141c9ee7e9 adoring_chebyshev 0.00% 12.96MiB / 3.548GiB 0.36% 1.38kB / 0B 0B / 0B 82
363bb5b36840 angry_chatelet 0.00% 1.086MiB / 3.548GiB 0.03% 1.6kB / 0B 0B / 0B 1
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
d865bdf33f88 container_C 94.79% 1.188MiB / 3.548GiB 0.03% 866B / 0B 0B / 0B 2
1fa168aaaf0a container_A 0.00% 1.18MiB / 3.548GiB 0.03% 1.01kB / 0B 0B / 0B 2
80c5fcbbe49d priceless_northcutt 0.00% 18.89MiB / 3.548GiB 0.52% 1.38kB / 0B 0B / 0B 82
b0141c9ee7e9 adoring_chebyshev 0.01% 12.96MiB / 3.548GiB 0.36% 1.38kB / 0B 0B / 0B 82
363bb5b36840 angry_chatelet 0.00% 1.086MiB / 3.548GiB 0.03% 1.6kB / 0B 0B / 0B 1
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
d865bdf33f88 container_C 94.79% 1.188MiB / 3.548GiB 0.03% 866B / 0B 0B / 0B 2
1fa168aaaf0a container_A 0.00% 1.18MiB / 3.548GiB 0.03% 1.01kB / 0B 0B / 0B 2
80c5fcbbe49d priceless_northcutt 0.00% 18.89MiB / 3.548GiB 0.52% 1.38kB / 0B 0B / 0B 82
b0141c9ee7e9 adoring_chebyshev 0.01% 12.96MiB / 3.548GiB 0.36% 1.38kB / 0B 0B / 0B 82
363bb5b36840 angry_chatelet 0.00% 1.086MiB / 3.548GiB 0.03% 1.6kB / 0B 0B / 0B 1
主机

1.086MiB / 3.548GiB 0.03% 1.6kB / 0B 0B / 0B 1
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
d865bdf33f88 container_C 94.79% 1.188MiB / 3.548GiB 0.03% 866B / 0B 0B / 0B 2
1fa168aaaf0a container_A 0.00% 1.18MiB / 3.548GiB 0.03% 1.01kB / 0B 0B / 0B 2
80c5fcbbe49d priceless_northcutt 0.00% 18.89MiB / 3.548GiB 0.52% 1.38kB / 0B 0B / 0B 82
b0141c9ee7e9 adoring_chebyshev 0.01% 12.96MiB / 3.548GiB 0.36% 1.38kB / 0B 0B / 0B 82
363bb5b36840 angry_chatelet 0.00% 1.086MiB / 3.548GiB 0.03% 1.6kB / 0B 0B / 0B 1
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
d865bdf33f88 container_C 94.79% 1.188MiB / 3.548GiB 0.03% 866B / 0B 0B / 0B 2
1fa168aaaf0a container_A 0.00% 1.18MiB / 3.548GiB 0.03% 1.01kB / 0B 0B / 0B 2
80c5fcbbe49d priceless_northcutt 0.00% 18.89MiB / 3.548GiB 0.52% 1.38kB / 0B 0B / 0B 82
b0141c9ee7e9 adoring_chebyshev 0.01% 12.96MiB / 3.548GiB 0.36% 1.38kB / 0B 0B / 0B 82
363bb5b36840 angry_chatelet 0.00% 1.086MiB / 3.548GiB 0.03% 1.6kB / 0B 0B / 0B 1
主机
[外链图片转存中...(img-IuFOgdZz-1778664478869)]
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐



所有评论(0)