Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services.down() fails if container_name is set in the dockerfile #21

Open
alxdca opened this issue Aug 8, 2022 · 3 comments
Open

services.down() fails if container_name is set in the dockerfile #21

alxdca opened this issue Aug 8, 2022 · 3 comments

Comments

@alxdca
Copy link

alxdca commented Aug 8, 2022

If the dockerfile defines the container name, then the calling services.down() fails as the down method looks for a container named with the following pattern:

projectName + '_' + serviceName + '_1'

In such case, the down method() should use the container_name defined in the dockerfile instead of its own naming format.

@Dr1Ku
Copy link

Dr1Ku commented Nov 18, 2022

Indeed, the dreaded message `'Conflict. The container name "/" is already in use by container "". You have to remove (or rename) that container to be able to reuse that name.'

One workaround, as based on the current implementation of down would be:

const projectContainers = await docker.listContainers({
  all: true,
  filters: { label: [`com.docker.compose.service=${serviceName}`] },
});

for await (const projectContainer of projectContainers) {
  const container = await docker.getContainer(projectContainer.Id);

  if (projectContainer.State === 'running') {
    console.log('Stopped running container', projectContainer);
    await container.stop();
  }

  await container.remove();
}  

Whereas serviceName is the name used under your docker-compose's services list/array.
One can also add one's own labels.

@TheDelta
Copy link

There hasn't been any progress on this issue and thankfully this was mentioned in here, because the error is "eaten" and I was confused why down is not working.

Am I missing something or is it really just taking the "container_name" property (or use default if it doesn't exist).
I'm willing to write a PR, just want to be sure I'm not missing something.

I also noticed there is an empty array services = [] which does nothing.
I would propose that this error will return successfull / unsucessfull downs, so a developer can react to this properly without being kept in the dark.

@ralexrdz
Copy link

I'm having a similar issue. compose.down() is not killing the containers

And also, compose.up() does not do what docker compose up -d command does, that is to replace current running containers with new version in case something in the config changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants