Skip to content

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

@akoskm

Description

@akoskm

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/[email protected]
        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]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions