mirror of
https://github.com/yeasy/docker_practice.git
synced 2025-09-02 02:42:23 +00:00
Compare commits
21 Commits
v1.3.0
...
ce4428adfb
Author | SHA1 | Date | |
---|---|---|---|
|
ce4428adfb | ||
|
6443ddc07c | ||
|
ce5ae6a360 | ||
|
35b264694b | ||
|
e76b0b66a0 | ||
|
d80f3430b2 | ||
|
d9c5d2fb43 | ||
|
fe7530c3f6 | ||
|
30f00323e0 | ||
|
93ea51ff07 | ||
|
85be3008fa | ||
|
88f9183fd5 | ||
|
1c4a43e34e | ||
|
7014e4d87c | ||
|
18028b8eaa | ||
|
7c78d1c256 | ||
|
d4c6e590c6 | ||
|
1e415ac76c | ||
|
664ac88c85 | ||
|
734079661d | ||
|
1ed8c2c81f |
13
.github/FUNDING.yml
vendored
Normal file
13
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: yeasy
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
@@ -167,9 +167,9 @@ RUN apt-get update && apt-get install -y \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
```
|
||||
|
||||
其中 `s3cmd` 指令指定了一个版本号 `1.1.*`。如果之前的镜像使用的是更旧的版本,指定新的版本会导致 `apt-get udpate` 缓存失效并确保安装的是新版本。
|
||||
其中 `s3cmd` 指令指定了一个版本号 `1.1.*`。如果之前的镜像使用的是更旧的版本,指定新的版本会导致 `apt-get update` 缓存失效并确保安装的是新版本。
|
||||
|
||||
另外,清理掉 apt 缓存 `var/lib/apt/lists` 可以减小镜像大小。因为 `RUN` 指令的开头为 `apt-get udpate`,包缓存总是会在 `apt-get install` 之前刷新。
|
||||
另外,清理掉 apt 缓存 `var/lib/apt/lists` 可以减小镜像大小。因为 `RUN` 指令的开头为 `apt-get update`,包缓存总是会在 `apt-get install` 之前刷新。
|
||||
|
||||
> 注意:官方的 Debian 和 Ubuntu 镜像会自动运行 apt-get clean,所以不需要显式的调用 apt-get clean。
|
||||
|
||||
@@ -329,7 +329,7 @@ $ docker run --rm -it postgres bash
|
||||
|
||||
如果某个服务不需要特权执行,建议使用 `USER` 指令切换到非 root 用户。先在 `Dockerfile` 中使用类似 `RUN groupadd -r postgres && useradd -r -g postgres postgres` 的指令创建用户和用户组。
|
||||
|
||||
>注意:在镜像中,用户和用户组每次被分配的 UID/GID 都是不确定的,下次重新构建镜像时被分配到的 UID/GID 可能会不一样。如果要依赖确定的 UID/GID,你应该显示的指定一个 UID/GID。
|
||||
>注意:在镜像中,用户和用户组每次被分配的 UID/GID 都是不确定的,下次重新构建镜像时被分配到的 UID/GID 可能会不一样。如果要依赖确定的 UID/GID,你应该显式的指定一个 UID/GID。
|
||||
|
||||
你应该避免使用 `sudo`,因为它不可预期的 TTY 和信号转发行为可能造成的问题比它能解决的问题还多。如果你真的需要和 `sudo` 类似的功能(例如,以 root 权限初始化某个守护进程,以非 root 权限执行它),你可以使用 [gosu](https://github.com/tianon/gosu)。
|
||||
|
||||
|
@@ -10,17 +10,17 @@ CentOS(Community Enterprise Operating System,中文意思是:社区企业
|
||||
|
||||
### 使用 CentOS 官方镜像
|
||||
|
||||
使用 `docker run` 直接运行最新的 `CentOS` 镜像,并登录 `bash`。
|
||||
使用 `docker run` 直接运行 `CentOS 7` 镜像,并登录 `bash`。
|
||||
|
||||
```bash
|
||||
$ docker run -it centos bash
|
||||
$ docker run -it centos:7 bash
|
||||
Unable to find image 'centos:latest' locally
|
||||
latest: Pulling from library/centos
|
||||
3d8673bd162a: Pull complete
|
||||
Digest: sha256:a66ffcb73930584413de83311ca11a4cb4938c9b2521d331026dad970c19adf4
|
||||
Status: Downloaded newer image for centos:latest
|
||||
[root@43eb3b194d48 /]# cat /etc/redhat-release
|
||||
CentOS Linux release 7.2.1511 (Core)
|
||||
CentOS Linux release 7.9.2009 (Core)
|
||||
```
|
||||
|
||||
## Fedora 系统简介
|
||||
|
@@ -40,7 +40,7 @@ FROM scratch
|
||||
|
||||
如果你以 `scratch` 为基础镜像的话,意味着你不以任何镜像为基础,接下来所写的指令将作为镜像第一层开始存在。
|
||||
|
||||
不以任何系统为基础,直接将可执行文件复制进镜像的做法并不罕见,对于 Linux 下静态编译的程序来说,并不需要有操作系统提供运行时支持,所需的一切库都已经在可执行文件里了,因此直接 `FROM scratch` 会让镜像体积更加小巧。使用 [Go 语言](https://golang.google.cn/) 开发的应用很多会使用这种方式来制作镜像,这也是为什么有人认为 Go 是特别适合容器微服务架构的语言的原因之一。
|
||||
不以任何系统为基础,直接将可执行文件复制进镜像的做法并不罕见,对于 Linux 下静态编译的程序来说,并不需要有操作系统提供运行时支持,所需的一切库都已经在可执行文件里了,因此直接 `FROM scratch` 会让镜像体积更加小巧。使用 [Go 语言](https://golang.google.cn/) 开发的应用很多会使用这种方式来制作镜像,这也是有人认为 Go 是特别适合容器微服务架构的语言的原因之一。
|
||||
|
||||
## RUN 执行命令
|
||||
|
||||
|
@@ -4,7 +4,7 @@ WORKDIR /app
|
||||
|
||||
COPY package.json /app/
|
||||
|
||||
RUN npm i --registry=https://registry.npm.taobao.org \
|
||||
RUN npm i --registry=https://registry.npmmirror.com \
|
||||
&& rm -rf ~/.npm
|
||||
|
||||
COPY src /app/src
|
||||
|
@@ -8,7 +8,7 @@ COPY package.json /app/
|
||||
|
||||
RUN --mount=type=cache,target=/app/node_modules,id=my_app_npm_module,sharing=locked \
|
||||
--mount=type=cache,target=/root/.npm,id=npm_cache \
|
||||
npm i --registry=https://registry.npm.taobao.org
|
||||
npm i --registry=https://registry.npmmirror.com
|
||||
|
||||
COPY src /app/src
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
# 参考文档
|
||||
|
||||
* `Dockerfie` 官方文档:https://docs.docker.com/engine/reference/builder/
|
||||
* `Dockerfile` 官方文档:https://docs.docker.com/engine/reference/builder/
|
||||
|
||||
* `Dockerfile` 最佳实践文档:https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
|
||||
|
||||
|
@@ -61,7 +61,7 @@ FROM node:alpine as frontend
|
||||
COPY package.json /app/
|
||||
|
||||
RUN set -x ; cd /app \
|
||||
&& npm install --registry=https://registry.npm.taobao.org
|
||||
&& npm install --registry=https://registry.npmmirror.com
|
||||
|
||||
COPY webpack.mix.js webpack.config.js tailwind.config.js /app/
|
||||
COPY resources/ /app/resources/
|
||||
@@ -179,7 +179,7 @@ FROM node:alpine as frontend
|
||||
COPY package.json /app/
|
||||
|
||||
RUN set -x ; cd /app \
|
||||
&& npm install --registry=https://registry.npm.taobao.org
|
||||
&& npm install --registry=https://registry.npmmirror.com
|
||||
|
||||
COPY webpack.mix.js webpack.config.js tailwind.config.js /app/
|
||||
COPY resources/ /app/resources/
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
## 系统要求
|
||||
|
||||
[Docker Desktop for Mac](https://docs.docker.com/docker-for-mac/) 要求系统最低为 macOS Mojave 10.14。
|
||||
[Docker Desktop for Mac](https://docs.docker.com/docker-for-mac/) 要求系统最低为 macOS 必须是 10.15 或更高版本, Catalina、Big Sur 或者 Monterey,建议升级到最新版本的 macOS。
|
||||
|
||||
## 安装
|
||||
|
||||
|
@@ -75,9 +75,9 @@ username/ubuntu
|
||||
|
||||
## 自动构建
|
||||
|
||||
> 2021 年 6 月 18 日之后,该项功能仅限[付费用户](https://www.docker.com/blog/changes-to-docker-hub-autobuilds/)使用。
|
||||
> 2021 年 7 月 26 日之后,该项功能仅限[付费用户](https://www.docker.com/blog/changes-to-docker-hub-autobuilds/)使用。
|
||||
|
||||
自动构建(`Automated Builds`)功能对于需要经常升级镜像内程序来说,十分方便。
|
||||
自动构建(`Automated Builds`)可以自动触发构建镜像,方便升级镜像。
|
||||
|
||||
有时候,用户构建了镜像,安装了某个软件,当软件发布新版本则需要手动更新镜像。
|
||||
|
||||
|
@@ -103,7 +103,7 @@ REPOSITORY TAG IMAGE ID CREAT
|
||||
|
||||
```json
|
||||
{
|
||||
"registry-mirror": [
|
||||
"registry-mirrors": [
|
||||
"https://hub-mirror.c.163.com",
|
||||
"https://mirror.baidubce.com"
|
||||
],
|
||||
|
@@ -62,7 +62,7 @@ $ docker service create \
|
||||
--network mysql_private \
|
||||
--publish target=30000,port=80 \
|
||||
--mount type=volume,source=wpdata,destination=/var/www/html \
|
||||
--secret source=mysql_password,target=wp_db_password,mode=0400 \
|
||||
--secret source=mysql_password,target=wp_db_password,mode=0444 \
|
||||
-e WORDPRESS_DB_USER="wordpress" \
|
||||
-e WORDPRESS_DB_PASSWORD_FILE="/run/secrets/wp_db_password" \
|
||||
-e WORDPRESS_DB_HOST="mysql:3306" \
|
||||
|
Reference in New Issue
Block a user