I am trying to create a multi stage Dockerfile, where the first stage is meant to be started in development environment (simple dev server) and the second stage is meant for production (full size web server).
FROM python:3.9-alpine3.14 as develop
...
CMD python manage.py runserver 0.0.0.0:8000
FROM python:3.9-alpine3.14 as production
...
CMD gunicorn -b 0.0.0.0:8000 backend.wsgi
I am trying to specify the target stage in docker-compose.yml like so:
version: '3.7'
services:
backend:
build:
target: develop
...
But it does not have any effect. Even when I set the target to OohEehOohAhAahTingTangWallaWallaBingBang
, there is no error and the production server (last stage in Dockerfile) starts.
So, how to specify which target should be started in docker-compose.yml ?
EDIT: I am using WSL (Windows Subsystem for Linux) with Ubuntu-20.04
$ docker-compose --version
Docker Compose version v2.0.0-rc.1
Ok, it seems that the behaviour of docker-compose is buggy. It DOES respect the target
but only when building - when running docker-compose up
, it just starts the image that was built last.
So if I set target: develop
, then docker-compose build
then docker-compose up
(or ... up --build
), then it will start the target develop
(simple dev server).
If I then set target: production
, then docker-compose build
then docker-compose up
(or ... up --build
), then it will start the target production
(full size server).
If I then set target: develop
again, then docker-compose build
then docker-compose up
(or ... up --build
), then it will start the target develop
(simple dev server).
Also, it only complains that the target does not exist when building images, not starting containers:
failed to create LLB definition: target stage OohEehOohAhAahTingTangWallaWallaBingBang could not be found