Docker:修订间差异
来自康健生活
| (未显示同一用户的74个中间版本) | |||
| 第1行: | 第1行: | ||
== 安装 == | |||
{| class="wikitable" | |||
|- | |||
| [[/macos|macos]] || 示例 || 示例 | |||
|} | |||
=== Ubuntu === | |||
{{shc|<syntaxhighlight lang="bash"> | |||
sudo apt remove docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc | |||
sudo apt install ca-certificates curl gnupg lsb-release | |||
export http_proxy=http://192.168.51.34:808 https_proxy=http://192.168.51.34:808 | |||
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg | |||
sudo echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |||
sudo apt clean && apt update | |||
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin | |||
unset http_proxy; unset https_proxy;</syntaxhighlight>|$|/home/kangkk}} | |||
网传另一种使用阿里源的方法,这里不做推荐,仅供参考 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |||
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"</syntaxhighlight>|$|/home/kangkk}} | |||
=== Compose === | |||
{{shc|<syntaxhighlight lang="bash"> | |||
sudo curl -SL https://github.com/docker/compose/releases/download/v2.29.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose | |||
sudo chmod +x /usr/local/bin/docker-compose</syntaxhighlight>|$|/home/kangkk}} | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker-compose --version</syntaxhighlight>|$|/home/kangkk}} | |||
== 源 == | |||
== docker == | == docker == | ||
{| class="wikitable" | {| class="wikitable" | ||
| 第4行: | 第36行: | ||
| [[/container_name|container name]] || 示例 || 示例 | | [[/container_name|container name]] || 示例 || 示例 | ||
|} | |} | ||
== 权限 == | |||
查看权限 | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
ls -l /var/run/docker.sock</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
srw-rw---- 1 root docker 0 Nov 21 15:42 /var/run/docker.sock | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
从 docker.sock 文件的状态信息中提取所有者的组 ID | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
stat -c '%g' /var/run/docker.sock</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
992 | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
添加当前用户到 docker 组。 | |||
<blockquote><pre> | |||
sudo groupadd docker | |||
sudo usermod -aG docker ${USER} | |||
sudo su | |||
su kangjian | |||
</pre></blockquote> | |||
{{shc|<syntaxhighlight lang="bash"> | |||
gpasswd -a $USER docker</syntaxhighlight>|$|/home/kangkk}} | |||
== docker.sock == | |||
如果 docker.sock 没有生效,可能会输出如下信息。 | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
curl -s --unix-socket /var/run/docker.sock http:/containers/json | jq .</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
{ | |||
"message": "page not found" | |||
} | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
正常信息如下 | |||
<pre> | |||
[ | |||
{ | |||
"Id": "b94a464760c7ef1f63486500b8e1f24c34ae934b6dac02d19336850faef8a543", | |||
"Names": [ | |||
"/runner1" | |||
], | |||
"Image": "drone/drone-runner-docker:1", | |||
"ImageID": "sha256:37113502465f8d42b091f08e7e25b48c613918ba810703565d0e59cd81d9c4d0", | |||
"Command": "/bin/drone-runner- | |||
... | |||
"RW": true, | |||
"Propagation": "rprivate" | |||
}, | |||
{ | |||
"Type": "bind", | |||
"Source": "/var/www/cii.qiwoo.org/log", | |||
"Destination": "/var/log/nginx", | |||
"Mode": "rw", | |||
"RW": true, | |||
"Propagation": "rprivate" | |||
} | |||
] | |||
} | |||
]</pre> | |||
== 参数 == | |||
=== --data-root === | |||
设置镜像存储路径。 | |||
== dockerfile == | == dockerfile == | ||
| 第20行: | 第113行: | ||
| 示例 || 示例 || 示例 | | 示例 || 示例 || 示例 | ||
|} | |} | ||
=== login === | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker login -u username -p password</syntaxhighlight>|$|/home/kangkk}} | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
echo 'D&u******&a7i' | docker login https://index.docker.io -u kangkk --password-stdin</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
Login Succeeded | |||
Logging in with your password grants your terminal complete access to your account. | |||
For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/ | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
== 应用 == | == 应用 == | ||
{| class="wikitable" | {| class="wikitable" | ||
| 第29行: | 第135行: | ||
| 示例 || 示例 || 示例 | | 示例 || 示例 || 示例 | ||
|} | |} | ||
== 数据卷 == | |||
指定目录挂载。 | |||
<blockquote><syntaxhighlight lang="bash"> | |||
docker run -it -v 主机目录:容器内目录</syntaxhighlight></blockquote> | |||
匿名挂载。 | |||
<blockquote><syntaxhighlight lang="bash"> | |||
docker run -it -v 容器内目录 | |||
# 主机目录默认为 /var/lib/docker/volumes/<id>/_data</syntaxhighlight></blockquote> | |||
具名挂载。 | |||
<blockquote><syntaxhighlight lang="bash"> | |||
docker run -it -v 自定义卷名:容器内目录 | |||
# 主机目录默认为 /var/lib/docker/volumes/<id>/_data</syntaxhighlight></blockquote> | |||
== 参数 == | == 参数 == | ||
=== --no-cache === | === --no-cache === | ||
| 第40行: | 第162行: | ||
|- | |- | ||
| 示例 || 示例 || 示例 | | 示例 || 示例 || 示例 | ||
|} | |} | ||
| 第57行: | 第173行: | ||
| 示例 || 示例 || 示例 | | 示例 || 示例 || 示例 | ||
|} | |} | ||
== 镜像 == | |||
=== 镜像列表 === | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
docker images</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
REPOSITORY TAG IMAGE ID CREATED SIZE | |||
node lts-alpine b1ca7421d2e7 2 days ago 112MB | |||
alpine 3.13.5 6dbb9cc54074 16 months ago 5.61MB | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
=== 镜像重命名 === | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker image tag node:lts-alpine kangkk.com/node:lts-alpine | |||
# or | |||
docker image tag b1ca7421d2e7 kangkk.com/node:lts-alpine</syntaxhighlight>|$|/home/kangkk}} | |||
再次查看镜像列表就可以看到新增的重命名之后的镜像了。 | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
docker images</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
REPOSITORY TAG IMAGE ID CREATED SIZE | |||
kangkk.com/node lts-alpine b1ca7421d2e7 2 days ago 112MB | |||
node lts-alpine b1ca7421d2e7 2 days ago 112MB | |||
alpine 3.13.5 6dbb9cc54074 16 months ago 5.61MB | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
== 制作镜像 == | == 制作镜像 == | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
| [[/nginxnode|nginxnode]]|| [[/centos|centos]] || | | [[/nginxnode|nginxnode]]|| [[/centos|centos]] || [[/yapi|yapi]] | ||
|- | |- | ||
| 示例 || 示例 || 示例 | | 示例 || 示例 || 示例 | ||
| 第66行: | 第208行: | ||
| 示例 || 示例 || 示例 | | 示例 || 示例 || 示例 | ||
|} | |} | ||
==== 导出镜像 ==== | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker save -o /root/images/image_name.tar image_name:latest</syntaxhighlight>|$|/home/kangkk}} | |||
==== 导入镜像 ==== | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker load < image_name.tar | |||
## | |||
docker load –i image_name.tar | |||
## | |||
docker load –input image_name.tar</syntaxhighlight>|$|/home/kangkk}} | |||
== 环境 == | == 环境 == | ||
| 第76行: | 第230行: | ||
| 示例 || 示例 || 示例 | | 示例 || 示例 || 示例 | ||
|} | |} | ||
== 镜像 == | |||
进入镜像。 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker run -it --entrypoint sh <镜像名称></syntaxhighlight>|$|/home/kangkk}} | |||
并挂载镜像地址(--privileged 设置 root 权限) | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker run -it --privileged -v <本地目录绝对路径>:<docker路径> --entrypoint sh <镜像名称></syntaxhighlight>|$|/home/kangkk}} | |||
开启一些服务会遇到 <code>Failed to connect to bus: Host is down</code> 错误。改为如下: | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker run -itd --privileged -v <本地目录绝对路径>:<docker路径> --name <自定义服务名称> <镜像名称> /usr/sbin/init \ | |||
docker exec -it <自定义服务名称> /bin/bash | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
下载镜像中的文件到本地磁盘。 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker cp <容器id>:<容器内地址> <本地地址></syntaxhighlight>|$|/home/kangkk}} | |||
示例。 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker cp ed8c1251c61c:/opt/app/src /Users/kangjian/Downloads</syntaxhighlight>|$|/home/kangkk}} | |||
=== 重新打包 === | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker commit -m "build nginx image" -a "kangkk" 5a9aa788a91e qnpm-nginx</syntaxhighlight>|$|/home/kangkk}} | |||
在重新打包的过程中,需要保持容器运行状态? | |||
运行容器 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker run -it d66f22a3c894 -i /bin/bash</syntaxhighlight>|$|/home/kangkk}} | |||
另起 tab 进入容器 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker exec -it 38de0181d5b4 bash</syntaxhighlight>|$|/home/kangkk}} | |||
最后 commit | |||
== 查看 == | == 查看 == | ||
我开始查询当前容器。但是抛出 docker 并未运行。 | 我开始查询当前容器。但是抛出 docker 并未运行。 | ||
| 第131行: | 第325行: | ||
{{shc|<syntaxhighlight lang="bash"> | {{shc|<syntaxhighlight lang="bash"> | ||
sudo docker inspect --format '{{.LogPath}}' 5f3d48017cd3</syntaxhighlight>|$|/home/kangkk}} | sudo docker inspect --format '{{.LogPath}}' 5f3d48017cd3</syntaxhighlight>|$|/home/kangkk}} | ||
== 启动 == | |||
=== 启动全部 === | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
sudo docker start $(sudo docker ps -a | awk '{ print $1}' | tail -n +2)</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
34b847559496 | |||
1aa50bf020ef | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
== 关闭 == | |||
=== 关闭全部 === | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
sudo docker stop $(sudo docker ps -a | awk '{ print $1}' | tail -n +2)</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
34b847559496 | |||
1aa50bf020ef | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
== 搜索 == | == 搜索 == | ||
| 第177行: | 第387行: | ||
</syntaxhighlight>|$|/home/kangkk}} | </syntaxhighlight>|$|/home/kangkk}} | ||
搜索历史版本。 | 搜索历史版本。{{Warning|已经失效}} | ||
{{Shc_out|<syntaxhighlight lang="bash"> | {{Shc_out|<syntaxhighlight lang="bash"> | ||
curl https://registry.hub.docker.com/v1/repositories/mysql/tags\ | curl https://registry.hub.docker.com/v1/repositories/mysql/tags\ | ||
| 第209行: | 第419行: | ||
mysql:oracle | mysql:oracle | ||
</syntaxhighlight>|$|/home/kangkk}} | </syntaxhighlight>|$|/home/kangkk}} | ||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
curl https://registry.hub.docker.com/_/mysql/tags | tr -d '[\[\]" ]' | tr '}' '\n'| awk -F: -v image='mysql' '{if(NR!=NF && $3 != ""){printf("%s:%s\n",image,$3)}}'</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
% Total % Received % Xferd Average Speed Time Time Time Current | |||
Dload Upload Total Spent Left Speed | |||
100 2271 100 2271 0 0 2042 0 0:00:01 0:00:01 --:--:-- 2055 | |||
mysql:300,400,400i,600,600i,700 | |||
mysql:400,500,600,700 | |||
mysql:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700&family=Roboto | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
== 添加 == | == 添加 == | ||
<blockquote><pre> | <blockquote><pre> | ||
| 第252行: | 第473行: | ||
* -f, -force: 强制删除镜像,即便有容器引用该镜像; | * -f, -force: 强制删除镜像,即便有容器引用该镜像; | ||
* -no-prune: 不要删除未带标签的父镜像; | * -no-prune: 不要删除未带标签的父镜像; | ||
删除所有镜像。 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
sudo docker rmi $(sudo docker images | awk '{print $3}' |tail -n +2)</syntaxhighlight>|$|/home/kangkk}} | |||
=== 删除容器 === | === 删除容器 === | ||
删除所有容器。 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
sudo docker rm $(sudo docker ps -a | awk '{ print $1}' | tail -n +2)</syntaxhighlight>|$|/home/kangkk}} | |||
== 宿主机创建数据目录和配置文件 == | == 宿主机创建数据目录和配置文件 == | ||
{{shc|<syntaxhighlight lang="bash"> | {{shc|<syntaxhighlight lang="bash"> | ||
| 第289行: | 第518行: | ||
sudo docker exec -it mysql-56 /bin/bash</syntaxhighlight>|$|/home/kangkk}} | sudo docker exec -it mysql-56 /bin/bash</syntaxhighlight>|$|/home/kangkk}} | ||
== 清理 == | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker system prune</syntaxhighlight>|$|/home/kangkk}} | |||
== error == | == error == | ||
{| class="wikitable" | {| class="wikitable" | ||
| 第306行: | 第538行: | ||
* Back-off restarting failed container | * Back-off restarting failed container | ||
: 实例事件中一直出现Back-off restarting failed container的Warning事件,一般是由于通过指定的镜像启动容器后,容器内部没有常驻进程,导致容器启动成功后即退出,从而进行了持续的重启。 | : 实例事件中一直出现Back-off restarting failed container的Warning事件,一般是由于通过指定的镜像启动容器后,容器内部没有常驻进程,导致容器启动成功后即退出,从而进行了持续的重启。 | ||
== 日志 == | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
sudo docker container ls -all</syntaxhighlight>|<syntaxhighlight lang="text"> | |||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |||
8edadee2b3f8 mysql:8.0 "docker-entrypoint..." 8 minutes ago Exited (1) 8 minutes ago mysql-80 | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
查看容器启动日志。 | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
sudo docker logs 8edadee2b3f8 | |||
</syntaxhighlight>|<syntaxhighlight lang="text"> | |||
2022-04-12 11:17:55+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.28-1debian10 started. | |||
2022-04-12 11:17:55+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' | |||
2022-04-12 11:17:55+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.28-1debian10 started. | |||
2022-04-12 11:17:55+00:00 [Note] [Entrypoint]: Initializing database files | |||
2022-04-12T11:17:55.534138Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release. | |||
2022-04-12T11:17:55.534234Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead. | |||
2022-04-12T11:17:55.534250Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.28) initializing of server in progress as process 41 | |||
2022-04-12T11:17:55.548592Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. | |||
2022-04-12T11:17:56.758459Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. | |||
2022-04-12T11:17:59.081271Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. | |||
2022-04-12 11:18:03+00:00 [Note] [Entrypoint]: Database files initialized | |||
2022-04-12 11:18:03+00:00 [Note] [Entrypoint]: Starting temporary server | |||
mysqld will log errors to /opt/datas/docker/mysql/data/4a0c074b7272.err | |||
mysqld is running as pid 90 | |||
2022-04-12 11:18:04+00:00 [Note] [Entrypoint]: Temporary server started. | |||
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it. | |||
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it. | |||
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it. | |||
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it. | |||
2022-04-12 11:18:06+00:00 [Note] [Entrypoint]: Stopping temporary server | |||
2022-04-12 11:18:08+00:00 [Note] [Entrypoint]: Temporary server stopped | |||
2022-04-12 11:18:08+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up. | |||
2022-04-12T11:18:09.290345Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release. | |||
2022-04-12T11:18:09.290508Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead. | |||
2022-04-12T11:18:09.290561Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.28) starting as process 1 | |||
2022-04-12T11:18:09.303870Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. | |||
2022-04-12T11:18:09.579432Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. | |||
2022-04-12T11:18:09.831051Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. | |||
2022-04-12T11:18:09.831094Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel. | |||
2022-04-12T11:18:09.861635Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock | |||
2022-04-12T11:18:09.861684Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.28' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL. | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
== inspect == | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
sudo docker inspect elasticsearch</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
[ | |||
{ | |||
"Id": "a9580fa1184b9cb5a6f945f4ee3235033699244903cb625694d2a0fc715abad9", | |||
"Created": "2021-05-30T07:36:52.122183052Z", | |||
"Path": "/usr/local/bin/docker-entrypoint.sh", | |||
"Args": [ | |||
"eswrapper" | |||
], | |||
... | |||
"GlobalIPv6PrefixLen": 0, | |||
"MacAddress": "02:42:ac:11:00:02", | |||
"DriverOpts": null | |||
} | |||
} | |||
} | |||
} | |||
] | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
=== IPAddress === | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
sudo docker inspect elasticsearch | grep IPAddress</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
"SecondaryIPAddresses": null, | |||
"IPAddress": "172.17.0.2", | |||
"IPAddress": "172.17.0.2", | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
== 网络 == | |||
查看网络状态。 | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
sudo docker network ls</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
NETWORK ID NAME DRIVER SCOPE | |||
2423ab85dd92 bridge bridge local | |||
d05fc848b239 host host local | |||
9213fe5ad3df none null local | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
参数: | |||
# bridge:桥接 docker | |||
# none:不配置网络 | |||
# host:和宿主机共享网络 | |||
# container:容器网络连通 | |||
=== bridge network === | |||
桥接网络 | |||
=== overlay network === | |||
=== MACVLAN network === | |||
=== 创建自定义网络 === | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
sudo docker network create --driver bridge --subnet 192.168.1.0/16 --gateway 192.168.1.0 kangkknet</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
1087cad22931daafb73b814cb28f531f57889ce5fbd85061cbc3ada7cf729272 | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
参数: | |||
# --driver bridge 表示使用桥接模式 | |||
# --subnet 192.168.1.0/16 表示子网ip,可以分配 192.168.1.2 到 192.168.255.255 | |||
# --gateway 192.168.1.0 表示网关 | |||
# kangkknet 表示网络名 | |||
检查添加状态。 | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
sudo docker network ls</syntaxhighlight>|<syntaxhighlight lang="bash" highlight="4"> | |||
NETWORK ID NAME DRIVER SCOPE | |||
2423ab85dd92 bridge bridge local | |||
d05fc848b239 host host local | |||
1087cad22931 kangkknet bridge local | |||
9213fe5ad3df none null local | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
网络相关信息。 | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
sudo docker network inspect kangkknet</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
[ | |||
{ | |||
"Name": "kangkknet", | |||
"Id": "1087cad22931daafb73b814cb28f531f57889ce5fbd85061cbc3ada7cf729272", | |||
"Created": "2022-04-28T17:08:54.05829233+08:00", | |||
"Scope": "local", | |||
"Driver": "bridge", | |||
"EnableIPv6": false, | |||
"IPAM": { | |||
"Driver": "default", | |||
"Options": {}, | |||
"Config": [ | |||
{ | |||
"Subnet": "192.168.1.0/16", | |||
"Gateway": "192.168.1.0" | |||
} | |||
] | |||
}, | |||
"Internal": false, | |||
"Attachable": false, | |||
"Ingress": false, | |||
"ConfigFrom": { | |||
"Network": "" | |||
}, | |||
"ConfigOnly": false, | |||
"Containers": {}, | |||
"Options": {}, | |||
"Labels": {} | |||
} | |||
] | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
== 存储空间映射 == | == 存储空间映射 == | ||
| 第317行: | 第703行: | ||
|- | |- | ||
| mysql || /etc/mysql/conf.d || /var/lib/mysql || /var/log/mysql || 1. MYSQL_ROOT_PASSWORD | | mysql || /etc/mysql/conf.d || /var/lib/mysql || /var/log/mysql || 1. MYSQL_ROOT_PASSWORD | ||
|- | |||
| gitlab || /etc/gitlab || /var/opt/gitlab || /var/log/gitlab || | |||
|- | |||
| postgresql || /etc/postgresql || /var/lib/postgresql/data || /var/log/postgresql || 1. POSTGRES_PASSWORD | |||
|} | |||
== 文件 == | |||
从复制容器内的文件到外面。 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker cp f6bbd9850c15:/usr/src/app /home/kangjian/data</syntaxhighlight>|$|/home/kangkk}} | |||
== 构建 == | |||
{| class="wikitable" | |||
|- | |||
| [[编程语言/Drone]] | |||
|} | |} | ||
== Volume == | |||
=== 类型 === | |||
* host volume:在宿主机上,可从容器内访问 | |||
* named volume:docker 管理 volume 位置,存在命名的名称 | |||
* anonymous volume:docker 管理 volume 位置,不存在命名的名称 | |||
=== type === | |||
==== bind ==== | |||
==== volume ==== | |||
==== tmpfs ==== | |||
如果是存储容器生成的非持久性状态数据,可以使用 [https://docs.docker.com/engine/storage/tmpfs/ tmpfs],在容器运行的整个生命周期内数据是有效的,可以避免写入容器的可写层来提高容器的性能,当容器重启后数据会消失。 | |||
=== 创建卷 === | |||
{{shc|<syntaxhighlight lang="bash"> | |||
sudo docker volume create vol</syntaxhighlight>|$|/home/kangkk}} | |||
tmpfs 卷 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker volume create -d local -o type=tmpfs -o device=tmpfs -o o=size=20480m,uid=1000 --name verdaccio_storage</syntaxhighlight>|$|/home/kangkk}} | |||
查看卷列表 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
sudo docker volume ls</syntaxhighlight>|$|/home/kangkk}} | |||
<pre> | |||
属性 描述 | |||
Driver 卷驱动 | |||
Labels 标签 | |||
Mountpoint 宿主机挂载点 | |||
Name 名称 | |||
Options 挂载参数 | |||
Scope 作用域</pre> | |||
使用格式化参数过滤信息 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
sudo docker volume ls --format "{{.Name}}: {{.Driver}}"</syntaxhighlight>|$|/home/kangkk}} | |||
卷详细信息 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
sudo docker volume inspect vol</syntaxhighlight>|$|/home/kangkk}} | |||
删除卷 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
sudo docker volume rm vol</syntaxhighlight>|$|/home/kangkk}} | |||
删除所有未在使用中的卷 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
sudo docker volume prune</syntaxhighlight>|$|/home/kangkk}} | |||
== 代理 == | |||
源于广义上存在的墙(或者两侧墙),Docker 非官方源不完成的情况下,只好使用代理进行镜像拉取。 | |||
编辑 Docker 源,设置为官方源。 | |||
{{hc|head=/etc/docker/daemon.json|output=<syntaxhighlight lang="bash"> | |||
{ | |||
"registry-mirrors": ["https://hub.docker.com/"] | |||
} | |||
</syntaxhighlight>}} | |||
编辑代理文件。 | |||
{{hc|head=/etc/systemd/system/docker.service.d/proxy.conf|output=<syntaxhighlight lang="bash"> | |||
[Service] | |||
Environment="HTTP_PROXY=http://192.168.51.34:808" | |||
Environment="HTTPS_PROXY=http://192.168.51.34:808" | |||
Environment="NO_PROXY=localhost,127.0.0.1,.example.com" | |||
</syntaxhighlight>}} | |||
重启 docker 后检查是否生效。 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
# 加载配置 | |||
systemctl daemon-reload | |||
# 重启docker | |||
systemctl restart docker | |||
# 查看代理配置是否生效 | |||
systemctl show --property=Environment docker | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
构建过程中代理 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
docker build . \ | |||
--build-arg "HTTP_PROXY=http://192.168.51.34:808/" \ | |||
--build-arg "HTTPS_PROXY=http://192.168.51.34:808/" \ | |||
--build-arg "NO_PROXY=localhost,127.0.0.1,.example.com" \ | |||
-t your/image:tag</syntaxhighlight>|$|/home/kangkk}} | |||
创建容器过程中代理容器的网络环境。 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
sudo docker run \ | |||
--restart=always \ | |||
--name=gogs \ | |||
--env HTTP_PROXY="http://192.168.51.34:808/" \ | |||
--env HTTPS_PROXY="http://192.168.51.34:808/" \ | |||
--env NO_PROXY="localhost,127.0.0.1,192.168.51.34" \ | |||
-p 10022:22 \ | |||
-p 10880:3000 \ | |||
-v /home/kangjian/gogs:/data \ | |||
-d gogs/gogs</syntaxhighlight>|$|/home/kangkk}} | |||
== 常见问题 == | == 常见问题 == | ||