前情提要:
这样一来,在服务器上执行的 docker-compose.yml 文件就需要修改了,不需要编译生成 Docker 镜像,直接用现成的镜像运行服务就可以了。
假设本地上传的镜像名称为 strapi:4.15.5
,要怎样修改下面的 yml 文件,才能让它直接用现成的镜像启动容器呢?
version: "3"
services:
strapi:
container_name: strapi
build: .
image: strapi:latest
restart: unless-stopped
env_file: .env
environment:
DATABASE_CLIENT: ${DATABASE_CLIENT}
DATABASE_HOST: strapiDB
DATABASE_PORT: ${DATABASE_PORT}
DATABASE_NAME: ${DATABASE_NAME}
DATABASE_USERNAME: ${DATABASE_USERNAME}
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
JWT_SECRET: ${JWT_SECRET}
ADMIN_JWT_SECRET: ${ADMIN_JWT_SECRET}
APP_KEYS: ${APP_KEYS}
NODE_ENV: ${NODE_ENV}
volumes:
- ./config:/opt/app/config
- ./src:/opt/app/src
- ./package.json:/opt/package.json
- ./yarn.lock:/opt/yarn.lock
- ./.env:/opt/app/.env
- ./public/uploads:/opt/app/public/uploads
ports:
- "1337:1337"
networks:
- strapi
depends_on:
- strapiDB
strapiDB:
container_name: strapiDB
env_file: .env
image: mysql:8.0.33
restart: always
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_USER: ${DATABASE_USERNAME}
MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD}
MYSQL_PASSWORD: ${DATABASE_PASSWORD}
MYSQL_DATABASE: ${DATABASE_NAME}
volumes:
- ./mysql_data:/var/lib/mysql
ports:
- "3306:3306"
networks:
- strapi
networks:
strapi:
name: Strapi
driver: bridge
1
sofukwird 354 天前 via Android
mysql:8.0.33@sha256:xxxxxx
带上 sha256 就不会联网检查是否有新版本了 |
2
kengfei 354 天前
把 build: . 删了
|
3
dream4ever OP @kengfei 多谢,原来这么简单🤣
|