How Docker Compose recreates the container on service version upgrade?
Answer a question
When I run the docker compose up command the docker-compose.yml is used to deploy the services as containers, whenever I again upgrade the version of services and redeploy the services the services gets re deployed again without any issue.
I am not sure how docker-compose keeps the track of the containers created using the docker compose file. I have this doubt because if the containers are created manually using with the same configuration and now the docker compose file is used to deploy the services. The docker compose file fails saying the container for the service already exists. If docker compose gives this error in case of container already existing why does it not give the same error when we upgrade the version and thereby red ploying the container.
Important point to note is that I do not use the standard convention where the docker compose creates container using the Project name instead I provide a name for each service container.
Thanks in advance. May be this question does not completely explain the purpose but I am new to Docker compose and I need to understand the architecture of how docker compose works.
Answers
Compose internally sets labels on the containers it launches. If you're especially interested you can see this in docker inspect low-level debugging output
"Labels": {
"com.docker.compose.config-hash": "92b5b683f86166dd554c49250c5b76f1bce2158fdccfa2047720e50cfc9b18fa",
"com.docker.compose.container-number": "1",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "x",
"com.docker.compose.project.config_files": "docker-compose.yml",
"com.docker.compose.project.working_dir": "********",
"com.docker.compose.service": "http",
"com.docker.compose.version": "1.25.2"
}
There are enough tricky details in here that I wouldn't try to impersonate this with docker run options; just re-run docker-compose up -d and have it recreate things for you.
You mention you have trouble because you explicitly set container_name:. That's not usually necessary. The Compose CLI includes most of the useful Docker CLI commands and addresses containers by their Docker Compose service name; in the Compose networking environment the service names are usable as hostnames. Letting Compose assign container names can avoid conflicts like what you're describing.
更多推荐
所有评论(0)