Docker Community Forums

Share and learn in the Docker community.

Create different containers from same settings

I work in a web development team that uses a relatively complex Docker-based setup. Some times I’d like to try out stuff that involves changes to Dockerfile or docker-compose.yml. Since the setup scripts can take quite long to run, it’d be great if I could make my changes in a separate location, so should I need to switch tasks quickly and get back to regular development work, I could just stop and start the appropriate containers.

I’m new to Docker and I still don’t fully grasp all the identifiers involved (container ID, image, tag, name…) or how they interact. I’ve browsed the project settings:

  • There’re 3 Dockerfile files but they don’t seem to set any identifier aside from some public images like php:7.2.24-fpm-alpine3.10, which I assume aren’t relevant here.

  • I think that docker-sync.yml and docker-compose-sync.yml belong to a third-party tool that’s used by colleagues with Macs so I can ignore it.

  • There’s finally docker-compose.yml and docker-compose.override.yml (there’s another docker compose file but it’s only needed to build some specific environment I don’t need). They define named identifiers for two kind of items (services and networks). Those names are also invoked in Docker commands by several internal scripts.

I run docker-compose up --build -d once to get started and I can omit --build afterwards.

What’s the best way to create a secondary setup from a different directory that doesn’t interfere with the first once? Do I need to physically rename the service names in YAML files or there’s a better way? Will that even work or it’ll overwrite my other containers due to some hash-based IDs?

(They don’t need to run simultaneously, so port conflicts shouldn’t be an issue).

1 Like