我想在已经在本地存储图像的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不使用本地存在的图像?
看起来你忘了指定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