docker: Error response from daemon: Conflict. The container name "/mongodb" is already in use by container
See original GitHub issueI’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:
- Created 2 years ago
- Comments:14 (13 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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:
localhost
as the host addresslocalhost
to connect to dependenciesWhile 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).
@eBsowka I’m still using the
docker-network
branch:@marcuspoehls do you remember why this wasn’t merged into master? Is it the issue with the network not being cleaned up?