question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

docker: Error response from daemon: Conflict. The container name "/mongodb" is already in use by container

See original GitHub issue

I’m trying to replace my old mongodb services setup with mongodb-github-action because it gives me an easy way to spin up a replica set.

Here’s my old setup:


    services:
      mongodb:
        image: mongo:4.2
        ports:
          - 27017:27017

I removed this and put the supercharge action in my build steps:

name: Build
# This workflow is triggered on pushes to the repository.
on: [push]

jobs:
  build:
    runs-on: self-hosted
    container: 10log/10log-base
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          persist-credentials: false

      - name: Use Node.js
        uses: actions/setup-node@v1
        with:
          node-version: '14'

      - name: MongoDB in GitHub Actions
        uses: supercharge/mongodb-github-action@1.4.1
        with:
          mongodb-version: '4.2'
          mongodb-replica-set: rs0


      - name: Install
        run: npm install

      - name: Bundle
        run: npm run build
        env:
          PAT_TOKEN: ${{ secrets.PAT_AKOSKM }}

      - name: Run unit tests
        env:
          MONGO_URI: mongodb://localhost:27017/test?replicaSet=rs0
        run: |
          ./version.sh
          npm run test-unit

      - name: Run client tests
        run: npm run test-client

      - name: Run integration tests
        env:
          MONGOLAB_URI: mongodb://mongodb/test?replicaSet=rs0
          MONGO_URI: mongodb://mongodb/test?replicaSet=rs0
        run: npm run test-integration

My problem is that the first test in the “Run unit tests” build step fails to connect to the mongodb instance:

(node:427) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16) {
  name: 'MongoNetworkError'
}]

but I think this is caused by an uncaught error that happens much earlier, in MongoDB in GithHub Actions:

Starting as single-node replica set (in replica set [rs0])
docker: Error response from daemon: Conflict. The container name "/mongodb" is already in use by container "ba21c3f0db068d6a3978d2217b8c012a181c7c748ade61c4d3e56cc1dfaff392". You have to remove (or rename) that container to be able to reuse that name.

For reference, here’s how the MongoDB in GithHub Actions command ends:

Initiating replica set [rs0]
MongoDB shell version v4.2.14
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("f3bb2a76-c258-4466-b7e2-8dc67b73a12d") }
MongoDB server version: 4.2.14
{
	"operationTime" : Timestamp(1622264561, 1),
	"ok" : 0,
	"errmsg" : "already initialized",
	"code" : 23,
	"codeName" : "AlreadyInitialized",
	"$clusterTime" : {
		"clusterTime" : Timestamp(1622264561, 1),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	}
}
Check! Initiated replica set [rs0]

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:14 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
marcuspoehlscommented, Jul 18, 2021

@akoskm @eBsowka Yeah, I remember why I never merged the docker-network branch: the GitHub Actions runner does not properly clean up the network used to connect all containers.

There are two ways of networking when using docker actions on a self-hosted runners:

  • you run your tests directly on the runner
    • you can connect to dependencies (like MongoDB) using localhost as the host address
  • you run your tests in another docker container
    • the runner creates a dedicated Docker network for all containers configured in the action’s workflow file
    • the runner then connects all containers to this dedicated network
    • your test can then use localhost to connect to dependencies
    • third-party actions (like this MongoDB container action) must also connect to the dedicated network
    • yet, there’s no step to tell the runner to disconnect third-party container actions to disconnect from the network or clean themselfs up when tearing down

While writing this, I think there’s a solution we can build into this MongoDB action: an input that disconnects the container from the network ensuring that your self-hosted runner can clean up correctly (remove container, remove the network).

0reactions
akoskmcommented, Jul 17, 2021

@eBsowka I’m still using the docker-network branch:

uses: supercharge/mongodb-github-action@docker-network

@marcuspoehls do you remember why this wasn’t merged into master? Is it the issue with the network not being cleaned up?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Docker error response from daemon: "Conflict ... already in ...
It looks like a container with the name qgis-desktop-2-4 already exists in the system. You can check the output of the below command...
Read more >
How to Fix the “Name Already in Use by Container” Error in ...
When running a docker container with a name we've used before, we'll encounter an error. We look at a few ways to resolve...
Read more >
The name "/data-container-name" is already used by ... - GitHub
docker : Error response from daemon: Conflict. The name "%name%" is already in use by container %container_id%. You have to remove (or rename)...
Read more >
Error response from daemon: Conflict. The container name is ...
docker : Error response from daemon: Conflict. The container name is already in use by container. In this article, we will see the...
Read more >
Docker error response from daemon: "Conflict already in use ...
Here you can watch how to resolve your docker conflicting issues with containers. You need to specify the container names uniquely else it ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found