2

I am using docker-compose to start 2 containers using the following docker-compose.yaml.

version: '2.4'

services:
  myservice1:
    container_name: mycontainername
    build: 
       context: .
       dockerfile: ./my-dockerfolder/Dockerfile
       args:       
       - MY_ARG=${MY_ARG}
    environment: 
       - MY_ARG=${MY_ARG}
    mem_limit: 3500M
    ports:
    - "9090:9090"
    extra_hosts:
    - "one.mydomain.net:127.0.0.1"
    - "two.mydomain.net:127.0.0.1"


  myservice2:
    container_name: myothercontainername
    build: 
       context: .
       dockerfile: ./other-dockerfolder/Dockerfile
       args: 
       - BUILD=${BUILD}
       - MY_ARG=${MY_ARG2}
    environment: 
       - MY_ARG2=${MY_ARG2}
    ports:
    - "2023:22"

My problem is that when I run docker-compose up again, it is using the same image to create the container, regardless of changes to the docker file.

How can I force it to take changes to the docker file into account?

Are other docker objects being reused that I need to be worried about? I want the second time I run docker-compose up to be as clean an environment as the first time.

note: I do not want to delete images that I do not need to delete. I have a slow connection to the docker repo, and removeing all the images would make my docker compose up take ~22 minutes.

2

Why not docker-compose build ?

https://docs.docker.com/compose/reference/build/

You can also do docker-compose up --build to force a rebuild.

  • Also worth noting that even if you build every time, Docker's built in cache means the image will only be rebuilt if you change the Dockerfile or any files that you are COPYing. – user2640621 Oct 14 '18 at 20:15
2

Use this command: docker-compose up --build

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.