Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

311
Views
Docker does not create a new container when using docker-compose build

I've set up two windows container for ASP.NET and MSSQL server. On the first docker-compose build everything works as expected. Then after I've made some changes to the custom dockerfile and run docker-compose build again it uses the old container again, not making any changes.

I assumed that when i did a build it created a new container. Am i misunderstanding how docker works?

This is the docker-compose.yml

version: '3'
services:
  db:
    image: microsoft/mssql-server-windows-developer

    environment:
      sa_password: "Password1234!"
      ACCEPT_EULA: "Y"

    ports:
      - "8003:1433"
    build:
      context: .
      dockerfile: mssql.dockerfile

  web:
    build:
      context: .
      dockerfile: web.dockerfile
    image: mcr.microsoft.com/dotnet/framework/aspnet:4.8
    #volumes:
    #  - .:C:/inetpub/wwwroot
    ports: 
      - "8080:80"
      - "8081:431"

This is the mssql.dockerfile

# escape=`

FROM microsoft/mssql-server-windows-developer

#set shell
SHELL ["powershell.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

#make temp folder
RUN mkdir C:\temp

#copy script to temp folder
COPY DownloadDatabase.ps1 C:\temp
COPY RestoreDatabase.ps1 C:\temp

#run script to retrieve production database
WORKDIR C:\temp

RUN .\DownloadDatabase.ps1 -sourcefile <url> -destinationfile <target>

CMD .\RestoreDatabase.ps1

It is very easy to tell if the image has been re-used because the mkdir C:\temp errors out saying the directory already exists.

EDIT: I've already tried all the options on docker compose. no-cache, force-rm

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

docker-compose build 

Only builds images but does not start containers.

That's why your changes in dockerfile are not applied. You have rebuilded the image but not the container. It's the reason why the container previoulsy launched is based on the older version of the image.

docker-compose up 

From Docker documentation :

If there are existing containers for a service, and the service’s configuration or image was changed after the container’s creation, docker-compose up picks up the changes by stopping and recreating the containers (preserving mounted volumes). To prevent Compose from picking up changes, use the --no-recreate flag.

In order to make shure that both of your image and container are rebuilded you have to add this flags :

docker-compose up --force-recreate --build

That way your containers are based on the correct image version.

Explanation on flags from Docker documentation :

--build                   Build images before starting containers.

--force-recreate          Recreate containers even if their configuration
                          and image haven't changed.

If you want to do this for a specific service just add the service name at the end of command line :

docker-compose up --force-recreate --build serviceName

Another flag useful if you want a clear output is the -d flag :

 -d, --detach              Detached mode: Run containers in the background,
                           print new container names. Incompatible with
over 4 years ago · Santiago Trujillo Report

0

It turns out i simply had to do docker-compose pull before docker-compose build to refresh the dockerfile! Now it builds a fresh image every time!

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!