Skip to content

Any way to simulate a suffix in container names? #415

Answered by sneko
sneko asked this question in Q&A
Discussion options

You must be logged in to vote

as mentioned in my initial question, I adopted the solution of suffixing my container names, so in my docker-compose.yaml I get for example:

version: '3.5'

services:
  postgres:
    container_name: postgres_container_${DOCKER_COMPOSE_CONTAINER_NAME_SUFFIX:-default}

Then in my test Jest environnement I do:

  const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
    .withEnvironment({
      DOCKER_COMPOSE_CONTAINER_NAME_SUFFIX: 'jest',
      POSTGRES_USER: dummyUser,
      POSTGRES_PASSWORD: dummyPassword,
      POSTGRES_DB: dummyDatabase,
    })

And to get the container so I can do .getMappedPort I simply use:

  const container = environment.getContainer('p…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@sneko
Comment options

@sneko
Comment options

Answer selected by cristianrgreco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants