我想在已经具有本地存储映像的Linux服务器上使用docker-compose运行应用程序。
该应用程序包含两个服务。在服务器上运行docker images
表示图像确实存在:
REPOSITORY TAG IMAGE ID CREATED SIZE
app_nginx latest b8362b71f3da About an hour ago 107MB
app_dash_alert_app latest 432f03c01dc6 About an hour ago 1.67GB
这是我的docker-compose.yml
:
version: '3'
services:
dash_alert_app:
container_name: dash_alert_app
restart: always
build: ./dash_alert_app
ports:
- "8000:8000"
command: gunicorn -w 1 -b :8000 dash_histogram_daily_counts:server
nginx:
container_name: nginx
restart: always
build: ./nginx
ports:
- "80:80"
depends_on:
- dash_alert_app
当我跑步时,docker-compose pull
似乎可以看到图像并将其拉入:
$ sudo docker-compose pull
Pulling dash_alert_app ... done
Pulling nginx ... done
但是当我尝试旋转容器时,我得到以下提示,仍然需要构建图像:
$ docker-compose up -d --no-build
ERROR: Service 'dash_alert_app' needs to be built, but --no-build was passed.
请注意,我已将docker配置为将图像存储在/mnt/data/docker
中-这是我的/etc/docker/daemon.json
文件:
{
"graph": "/mnt/data/docker",
"storage-driver": "overlay",
"bip": "192.168.0.1/24"
}
这是我的文件夹结构:
.
│ docker-compose.yml
└───dash_alert_app
└───nginx
为什么docker-compose不使用本地存在的图像?
答案 0 :(得分:2)
好像您忘记了指定image
键。另外,您是否真的必须使用docker-compose build
重新构建映像,或者现有的映像是否足够?如果是这样,请尝试以下操作:
version: '3'
services:
dash_alert_app:
image: app_dash_alert_app
container_name: dash_alert_app
restart: always
ports:
- "8000:8000"
command: gunicorn -w 1 -b :8000 dash_histogram_daily_counts:server
nginx:
image: app_nginx
container_name: nginx
restart: always
ports:
- "80:80"
depends_on:
- dash_alert_app