shubham gupta
shubham gupta

Reputation: 61

Can I recreate a Docker container with docker-compose up without deleting the old one?

I am working on Node Js application, and for every new release I want to create a new Docker with new image (image name is pass as variable in Docker Compose), but without deleting the old one, as I want to do version controlling?

My Docker-Compose File is as


    version: '3' 
        services: 
                web:
                   build: . 
                   image: ${IMAGE_NAME} 
                   container_name: ${CONTAINER_NAME} 
                   ports: 
                        - ${PORT}:8447

Command I run is docker-compose up -d but this will delete my old container and start a new one.

Upvotes: 2

Views: 1630

Answers (1)

redhatvicky
redhatvicky

Reputation: 1930

Its not ideal to have multiple versions of the container , but we can have updated version of images using tag.You can tag the image with the version number.Compose will build and tag it with a generated name, and use that image thereafter to create containers.

So whenever you have a new build you will a new image of the build with the tag and with that you can track the versions of the build versions.

Here below is the link which can help how to tag a image from Docker Compose:

How to tag docker image with docker-compose

But if you want to run multiple instances of the container with the same image , you can use scale:

docker-compose up -d --scale <imageName>=5

You can also do that using "replicas" inside your compose file itself.

deploy:
      mode: replicated
      replicas: 5

Source : https://docs.docker.com/compose/compose-file/#replicas

Upvotes: 2

Related Questions