Let's say we have the following docker-compose.yml
:
version: '3'
services:
db:
image: "postgres"
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=mysecretpassword
web:
build: web
depends_on: [ db ]
ports:
- "80:80"
The first service, db
, just runs a container with the official postgres image from Docker Hub.
The second service, web
, first builds a new image based on the Dockerfile
in a folder also called web
, then runs a container with that image.
While developing, we now can (repeatedly) make changes to whatever is in the web
folder, then run docker-compose up --build
to run our app locally.
Let's say we now want to deploy to production. My understanding is that docker-compose.yml
can now be used to "define a stack in Docker's swarm mode" (see this answer, for instance). However, for the build
step of the web
service, Docker's compose file documentation states that
This option is ignored when deploying a stack in swarm mode with a (version 3) Compose file. The docker stack command accepts only pre-built images.
It probably wouldn't be a great idea to build the image on the production machine anyways, as this would leave build artifacts (source code) behind; this should happen on a build server.
My question is, is there a recommended way to modify docker-compose.yml
en route to production to swap out build: web
with image: <id>
somehow?
Nothing on Use Compose in production on that. Is there something wrong with my approach in general?