下载镜像
[root@192 ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
45b42c59be33: Pull complete
d0d9e9ea897e: Pull complete
66e650438339: Pull complete
76a3dfe4406b: Pull complete
410ff9d97480: Pull complete
Digest: sha256:1a53eb723d17523512bd25c27299046cfa034cce309f4ed330c943a304513f59
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
启动容器
相关命令:
运行:docker run
[root@192 ~]# docker run -d --name mynginx -p 80:80 nginx
26bf99ddd8cecd94442272f9df7c03101afebd3b27e7625eb02624776e589a50
查看:docker ps
[root@192 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9b81186a41f8 nginx "/docker-entrypoint.…" 16 seconds ago Up 14 seconds 80/tcp sharp_taussig
查看所有的容器
[root@192 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26b42c41dda6 9bbf2937ac71 "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp app01
停止:docker stop
docker stop 容器id
启动:docker start
[root@192 ~]# docker start sharp_taussig
sharp_taussig
重启:docker restart
docker restart 容器id
状态:docker stats
docker stats 容器id
日志:docker logs
docker logs -f 容器id
[root@192 ~]# docker logs -f 26b42c41dda6
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: IPv6 listen already enabled
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
192.168.75.1 - - [27/Aug/2024:07:11:00 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" "-"
192.168.75.1 - - [27/Aug/2024:07:11:01 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" "-"
192.168.75.1 - - [27/Aug/2024:07:11:01 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" "-"
192.168.75.1 - - [27/Aug/2024:07:11:01 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" "-"
192.168.75.1 - - [27/Aug/2024:07:14:52 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" "-"
192.168.75.1 - - [27/Aug/2024:07:14:53 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" "-"
192.168.75.1 - - [27/Aug/2024:07:14:53 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" "-"
192.168.75.1 - - [27/Aug/2024:07:14:53 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" "-"
192.168.75.1 - - [27/Aug/2024:07:14:53 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" "-"
192.168.75.1 - - [27/Aug/2024:07:15:08 +0000] "GET / HTTP/1.1" 200 22 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0" "-"
2024/08/27 07:15:08 [error] 22#22: *5 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.75.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.75.152", referrer: "http://192.168.75.152/"
192.168.75.1 - - [27/Aug/2024:07:15:08 +0000] "GET /favicon.ico HTTP/1.1" 404 555 "http://192.168.75.152/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0" "-"
进入:docker exec
[root@192 ~]# docker exec -it 26b42c41dda6 /bin/bash
root@26b42c41dda6:/#
删除:docker rm
必须停止才能删除
docker rm 容器id
强制删除
docker rm -f 容器id
批量删除
docke rm -f $(docker ps -aq)
修改页面
root@26bf99ddd8ce:/usr/share/nginx# echo "<h1>Hello Docker</h1>" > html/index.html
保存镜像
- 提交:docker commit
- 保存:docker save
- 加载:docker load
提交
[root@192 ~]# docker commit -m "update index.html" mynginx mynginx:v1.0
sha256:9bbf2937ac719681878980c50150e598d07cf0e25d100056fd928e3606f67b92
[root@192 ~]#
[root@192 ~]#
[root@192 ~]#
[root@192 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mynginx v1.0 9bbf2937ac71 4 seconds ago 133MB
nginx latest 298ec0e28760 3 years ago 133MB
保存
[root@192 ~]# docker save -o mynginx.tar mynginx:v1.0
[root@192 ~]# ll
总用量 133992
-rw-------. 1 root root 1404 8月 26 20:39 anaconda-ks.cfg
-rw-------. 1 root root 137201664 8月 27 15:07 mynginx.tar
加载
[root@192 ~]# docker load -i mynginx.tar
9eb82f04c782: Loading layer [==================================================>] 72.49MB/72.49MB
4cbb728cd302: Loading layer [==================================================>] 64.65MB/64.65MB
c20672db3628: Loading layer [==================================================>] 3.072kB/3.072kB
ae1f545e4c08: Loading layer [==================================================>] 4.096kB/4.096kB
d9eb91d66e2a: Loading layer [==================================================>] 3.584kB/3.584kB
cc4d20bddab2: Loading layer [==================================================>] 17.41kB/17.41kB
Loaded image: mynginx:v1.0
[root@192 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mynginx v1.0 9bbf2937ac71 5 minutes ago 133MB
分享社区
- 登录:docker login
- 命名:docker tag
- 推送:docker push
登录
docker login -u cn-north-4@xxxxxxxxx-p 密码xxxx swr.cn-north-4.myhuaweicloud.com
命名
[root@192 ~]# docker tag mynginx:v1.0 swr.cn-north-4.myhuaweicloud.com/yohoo/mynginx:v1.0
[root@192 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mynginx v1.0 9bbf2937ac71 24 minutes ago 133MB
swr.cn-north-4.myhuaweicloud.com/yohoo/mynginx v1.0 9bbf2937ac71 24 minutes ago 133MB
推送
[root@192 ~]# docker push swr.cn-north-4.myhuaweicloud.com/yohoo/mynginx:v1.0
The push refers to repository [swr.cn-north-4.myhuaweicloud.com/yohoo/mynginx]
cc4d20bddab2: Pushed
d9eb91d66e2a: Pushed
ae1f545e4c08: Pushed
c20672db3628: Pushed
4cbb728cd302: Pushed
9eb82f04c782: Pushed
v1.0: digest: sha256:9da9edc675f146e568e6443138770df469f5031b8be364b43916ffe93481c4f0 size: 1570