Open Arondight opened 3 years ago
跑一下下面的指令就好了
# mkdir -pv ./data/nginx-logs/ ./data/frontend-usr/
我感觉是不是要在文档上注明一下?
这是不符合预期的,这两个文件夹按理说应当被自动创建,待我本地测试一下,看能不能复现先。
# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
不仅仅是我说的那两个目录,所有的目录都需要手动创建。
# mkdir -pv $(grep -oP '(?<=-\h)[^\d]+?(?=:)' ./docker-compose.yml)
麻烦尝试一下运行 docker run --rm -v "${PWD}/test:/pwd" busybox:latest sh
命令,看下运行完之后,会不会有一个名为 test
的文件夹被创建。
[root@nebula-centos-7 PasteMe]# ls
docker-compose.yml
[root@nebula-centos-7 PasteMe]# docker run --rm -v "${PWD}/test:/pwd" busybox:latest sh
Unable to find image 'busybox:latest' locally
Trying to pull repository docker.io/library/busybox ...
latest: Pulling from docker.io/library/busybox
24fb2886d6f6: Pull complete
Digest: sha256:f7ca5a32c10d51aeda3b4d01c61c6061f497893d7f6628b92f822f7117182a57
Status: Downloaded newer image for docker.io/busybox:latest
WARNING: IPv4 forwarding is disabled. Networking will not work.
[root@nebula-centos-7 PasteMe]# tree
.
├── docker-compose.yml
└── test
1 directory, 1 file
[root@nebula-centos-7 PasteMe]# ls
docker-compose.yml
[root@nebula-centos-7 PasteMe]# docker run --rm -v "${PWD}/test/1/2/3/:/pwd" busybox:latest sh
WARNING: IPv4 forwarding is disabled. Networking will not work.
[root@nebula-centos-7 PasteMe]# tree
.
├── docker-compose.yml
└── test
└── 1
└── 2
└── 3
4 directories, 1 file
辛苦再试下这个 docker-compose.yml
,看看执行 docker-compose up
之后,有没有 test_dir
被创建。
version: "3"
services:
busybox:
image: busybox:latest
volumes:
- ./test_dir:/pwd
[root@nebula-centos-7 PasteMe]# ls
docker-compose.yml
[root@nebula-centos-7 PasteMe]# cat docker-compose.yml
version: "3"
services:
busybox:
image: busybox:latest
volumes:
- ./test_dir:/pwd
[root@nebula-centos-7 PasteMe]# docker-compose up
WARN[0000] Found orphan containers ([pasteme-mysql]) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
[+] Running 1/0
⠿ Container pasteme-busybox-1 Created 0.0s
Attaching to pasteme-busybox-1
pasteme-busybox-1 exited with code 0
[root@nebula-centos-7 PasteMe]# tree
.
├── docker-compose.yml
└── test_dir
1 directory, 1 file
我顺手在 CentOS 8 上试了一下,一样的问题。
[root@localhost PasteMe]# docker-compose up -d
[+] Running 0/0
⠋ Container pasteme-backend Creating 0.0s
Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /opt/PasteMe/data/backend-config
[root@localhost PasteMe]# cat /etc/centos-release
CentOS Linux release 8.4.2105
[root@localhost PasteMe]# docker-compose -v
Docker Compose version v2.0.1
[root@localhost PasteMe]# docker -v
Docker version 20.10.8, build 3967b7d
我去,这就很奇怪了。
因为创建文件夹这一步,是由 docker
来进行的,不受我的管控,如果我刚才提到的两步都没问题的话,按理说,也不应该有这个问题。
参考这份文档,我觉得可能是在你的 compose 配置中,docker-compose
认为你用到了 bind-mounts
特性。
If you bind mount a host path into your service’s containers, the path must exist on every swarm node. The Docker swarm mode scheduler can schedule containers on any machine that meets resource availability requirements and satisfies all constraints and placement preferences you specify.
好的,感谢。超出我所了解的范畴了,我有空研究下。
此外我在本地进行了尝试,是没有问题的。
(python3) root@debian:~/pasteme# uname -a
Linux debian 4.19.0-12-amd64 #1 SMP Debian 4.19.152-1 (2020-10-18) x86_64 GNU/Linux
(python3) root@debian:~/pasteme# docker-compose --version
docker-compose version 1.28.2, build unknown
(python3) root@debian:~/pasteme# docker --version
Docker version 19.03.13, build 4484c46d9d
(python3) root@debian:~/pasteme# tree .
.
└── docker-compose.yml
0 directories, 1 file
(python3) root@debian:~/pasteme# cat docker-compose.yml
version: "3"
services:
pasteme-frontend:
image: pasteme/frontend:3.4.2
container_name: pasteme-frontend
depends_on:
- pasteme-backend
healthcheck:
test: ["CMD", "curl", "-so", "/dev/null", "localhost:8080/usr/config.json"]
interval: 45s
timeout: 3s
retries: 3
restart: always
ports:
- 80:8080
volumes:
- ./data/nginx-logs/:/var/lib/pasteme/
- ./data/frontend-usr/:/www/pasteme/usr/
pasteme-backend:
image: pasteme/go-backend:3.5.2
container_name: pasteme-backend
depends_on:
- pasteme-mysql
healthcheck:
test: ["CMD", "wget", "-O", "/dev/null", "localhost:8000/api/v3/?method=beat"]
interval: 45s
timeout: 3s
retries: 3
restart: always
volumes:
- ./data/backend-config/:/etc/pastemed/
logging:
driver: "json-file"
options:
max-file: "3"
max-size: "128m"
pasteme-mysql:
image: mysql:5.5
container_name: pasteme-mysql
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
interval: 45s
timeout: 3s
retries: 3
restart: always
command: [
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_unicode_ci'
]
environment:
MYSQL_USER: username
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: pasteme
MYSQL_MAX_ALLOWED_PACKET: 128M
MYSQL_INNODB_LOG_FILE_SIZE: 64M
volumes:
- ./data/mysql:/var/lib/mysql
logging:
driver: "json-file"
options:
max-file: "3"
max-size: "128m"
(python3) root@debian:~/pasteme# docker-compose up -d
Building with native build. Learn about native build in Compose here: https://docs.docker.com/go/compose-native-build/
Creating network "pasteme_default" with the default driver
Creating pasteme-mysql ... done
Creating pasteme-backend ... done
Creating pasteme-frontend ... done
(python3) root@debian:~/pasteme# tree .
.
├── data
│ ├── backend-config
│ │ └── config.json
│ ├── frontend-usr
│ │ ├── config.json
│ │ └── usr.js
│ ├── mysql
│ │ └── ...
│ └── nginx-logs
│ ├── pasteme.error.log
│ └── pasteme.log
└── docker-compose.yml
8 directories, 101 files
建议你把 docker-compose
版本拉到最新再试一下。
你这个问题在你那边可以稳定复现吗?
我把 docker-compose.yml
和 docker
都更新到了最新版本,看起来是没有问题的。
(python3) root@debian:~/pasteme# uname -a
Linux debian 4.19.0-18-amd64 #1 SMP Debian 4.19.208-1 (2021-09-29) x86_64 GNU/Linux
(python3) root@debian:~/pasteme# docker-compose --version
docker-compose version 1.29.2, build unknown
(python3) root@debian:~/pasteme# docker --version
Docker version 20.10.10, build b485636
(python3) root@debian:~/pasteme# tree .
.
└── docker-compose.yml
0 directories, 1 file
(python3) root@debian:~/pasteme# cat docker-compose.yml
version: "3"
services:
pasteme-frontend:
image: pasteme/frontend:3.4.2
container_name: pasteme-frontend
depends_on:
- pasteme-backend
healthcheck:
test: ["CMD", "curl", "-so", "/dev/null", "localhost:8080/usr/config.json"]
interval: 45s
timeout: 3s
retries: 3
restart: always
ports:
- 80:8080
volumes:
- ./data/nginx-logs/:/var/lib/pasteme/
- ./data/frontend-usr/:/www/pasteme/usr/
pasteme-backend:
image: pasteme/go-backend:3.5.2
container_name: pasteme-backend
depends_on:
- pasteme-mysql
healthcheck:
test: ["CMD", "wget", "-O", "/dev/null", "localhost:8000/api/v3/?method=beat"]
interval: 45s
timeout: 3s
retries: 3
restart: always
volumes:
- ./data/backend-config/:/etc/pastemed/
logging:
driver: "json-file"
options:
max-file: "3"
max-size: "128m"
pasteme-mysql:
image: mysql:5.5
container_name: pasteme-mysql
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
interval: 45s
timeout: 3s
retries: 3
restart: always
command: [
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_unicode_ci'
]
environment:
MYSQL_USER: username
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: pasteme
MYSQL_MAX_ALLOWED_PACKET: 128M
MYSQL_INNODB_LOG_FILE_SIZE: 64M
volumes:
- ./data/mysql:/var/lib/mysql
logging:
driver: "json-file"
options:
max-file: "3"
max-size: "128m"
(python3) root@debian:~/pasteme# docker-compose up -d
Creating network "pasteme_default" with the default driver
Creating pasteme-mysql ... done
Creating pasteme-backend ... done
Creating pasteme-frontend ... done
(python3) root@debian:~/pasteme# tree .
.
├── data
│ ├── backend-config
│ │ └── config.json
│ ├── frontend-usr
│ │ ├── config.json
│ │ └── usr.js
│ ├── mysql
│ │ └── ...
│ └── nginx-logs
│ ├── pasteme.error.log
│ └── pasteme.log
└── docker-compose.yml
8 directories, 100 files
稳定复现