Mongodb docker container exit instantly after starting - mongodb

Hello im trying to create a docker container for Mongodb
Install worked well and everything looked fine at docker ps --all
But when i started the Docker and then did docker ps --all again it shows up like Exited (14) 3 seconds ago... So for me it looks like that it instantly after starting the docker exited it, and cause of that i cant run any commands like docker exec -it (ID) bash because i get a deamon Error that the container is not running.
What can i do about that? Google solutions didnt helped until now...
Infos
- Ubuntu Version: 20.04 Focal
- Image: mongo:4.4-focal and mongo
- Docker Version: 20.10.7
Commands Used
Installed with: docker run mongo:4.4-focal
Command im running: docker start (ID)
Docker answers with printing ID (like it should when the Container is online)
Command im running: docker exec -it (ID) bash
Error: Error response from daemon: Container (A longer ID) is not running

Related

Unable to run docker container for mongodb 2.6.12

I need mongodb specific version and when I run the following command, it runs the container but exit quickly
docker run --name some-mongo -d mongo:2.6.12
4bbe88021ad919ba9680a2a4710e664a87e8620d4cd9802567029fec131534a3
If I list the containers docker ps -a, I can see following output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4bbe88021ad9 mongo:2.6.12 "/entrypoint.sh mong…" 4 seconds ago Exited (139) 3 seconds ago some-mongo
I am not sure why its existing and hence tried the logs
docker logs 4bbe88021ad9 but the is result empty (no result at all)
Please note the lates version works fine
docker run -p 27031:27017 --name kongoLatest -d mongo
I need to investiage why its not working for specific version? The main process must be failing and throwing some error which I am not able to see it.

Docker toolbox on windows 10. Bind for 0.0.0.0:8081 failed: port is already allocated error

I have setup docker toolbox on windows 10. While building the project I encountered the following error :- Bind for 0.0.0.0:8081 failed: port is already allocated ? The sudo service docker restart command isn't working. Please provide me a solution for the same.
Generally speaking, you need to stop running the current container. For that you are going to know current CONTAINER ID:
$ docker container ls
You get something like:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
97a32e8928ef friendlyhello "python app.py" 51 seconds ago Up 50 seconds 0.0.0.0:4000->80/tcp romantic_tesla
Then you stop the container by:
$ docker stop 97a32e8928ef
Finally, you try to do what you wanted to do, for example:
$ docker run -p 4000:80 friendlyhello
Commonly if this error happens, I restarting my winnat with commands:
$ net stop winnat
// build your project
$ net start winnat
If that doesnt help. I restart whole docker with commands:
wsl --unregister docker-desktop
wsl --unregister docker-desktop-data
Then docker offers to restart docker-service.

Docker Swarm mode - equivalent docker commands to docker run -it ubuntu

I am trying to deploy a mongodb cluster on docker swarm mode, all the mongod daemon are in the same overlay network.
I need to configure the mongodb cluster, i am trying to find a command that works like docker run -it ubuntu in docke rswarm mode so i can log in, any ideas?
Or is there any other way to access the overlay network.
SOLUTION:
First ssh to the node that runs the container, then find out the container id using docker ps and simply use docker exec -it $(id) bash to log on to the container.

how to remove non existent docker image

I am trying to run repair command for mongod, but daemon gave conflict error, so i removed the container and again run the repair command and daemon gave again same conflict error, this time i removed container with the container id displayed in the error and daemon says "no such id".
So, can anyone let me know that how can i remove this container so that i can successfully run the repair command.
I am displaying my docker commands as below for reference
Below is my docker ps result
root#ip-172-31-6-252:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
1f7bdd83dac0 mongo:latest "/entrypoint.sh mong 23 hours ago Up 23 hours 27017/tcp
cpx.db
11e2123f7e2a centralpx/cpx.server:latest "/run.sh" 2 weeks ago Up 2 weeks 0.0.0.0:80->80/tcp
cpx.server.live
4008c7772f63 centralpx/cpx-ftp "/bin/sh -c '/usr/sb 7 months ago Up 4 months 0.0.0.0:21->21/tcp, 0.0.0.0:30000-30009->30000-30009/tcp cpx.ftp
Below is my docker images result
root#ip-172-31-6-252:~# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
mongo latest 21e69f355287 8 days ago 366.4 MB
centralpx/cpx.server latest 894a3c5fce73 2 weeks ago 429 MB
centralpx/cpx-ftp latest e35ba5efa239 9 months ago 425.5 MB
Now i get attached to cpx.db container and run shutdown command (i need to shutdown before running repair command)
root#ip-172-31-6-252:~# docker exec -it cpx.db /bin/bash
root#1f7bdd83dac0:/# mongod --shutdown
killing process with pid: 1
FATA[0026] Error response from daemon: Container 1f7bdd83dac037293d5086e86a3df7117b4b6eb2a3478d65848643eff9c4d568 is not running: Exited (0) Less than a second ago
root#ip-172-31-6-252:~#
Now below is my repair command
root#ip-172-31-6-252:~# sudo docker run -it -p 28001:27017 --name cpx.db mongo:latest mongod --dbpath /data/db --repair
FATA[0000] Error response from daemon: Conflict. The name "cpx.db" is already in use by container 8b2a8c98971c. You have to delete (or rename) that container to be able to reuse that name.
The above command gives conflict error, so we removed the container "cpx.db", below is the docker commands
root#ip-172-31-6-252:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1f7bdd83dac0 mongo:latest "/entrypoint.sh mong 23 hours ago Exited (0) 3 minutes ago cpx.db
11e2123f7e2a centralpx/cpx.server:latest "/run.sh" 2 weeks ago Up 2 weeks 0.0.0.0:80->80/tcp cpx.server.live
4008c7772f63 centralpx/cpx-ftp "/bin/sh -c '/usr/sb 7 months ago Up 4 months 0.0.0.0:21->21/tcp, 0.0.0.0:30000-30009->30000-30009/tcp cpx.ftp
root#ip-172-31-6-252:~# docker rm cpx.db
cpx.db
root#ip-172-31-6-252:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
11e2123f7e2a centralpx/cpx.server:latest "/run.sh" 2 weeks ago Up 2 weeks 0.0.0.0:80->80/tcp cpx.server.live
4008c7772f63 centralpx/cpx-ftp "/bin/sh -c '/usr/sb 7 months ago Up 4 months 0.0.0.0:21->21/tcp, 0.0.0.0:30000-30009->30000-30009/tcp cpx.ftp
Then we again run repair command as the conflicting container is removed and below is our command and output
root#ip-172-31-6-252:~# sudo docker run -it -p 28001:27017 --name cpx.db mongo:latest mongod --dbpath /data/db --repair
FATA[0000] Error response from daemon: Conflict. The name "cpx.db" is already in use by container 8b2a8c98971c. You have to delete (or rename) that container to be able to reuse that name.
Daemon again gave conflict error
We again removed the container with id shown in conflict message as below, and it shows no such id. Please refer below
root#ip-172-31-6-252:~# docker rm 8b2a8c98971c
Error response from daemon: no such id: 8b2a8c98971c
FATA[0000] Error: failed to remove one or more containers
So, can any one help us to remove this container which doesn't exists or can anyone help us to get rid of this issue.
As you pointed the problem in command of instantiating the stopped container so i tried to correct my mistake in the command and run this command
sudo docker mongod --dbpath /data/db --repair
this command gives error
docker: 'mongod' is not a docker command. See 'docker --help'
and if i remove docker from command and run this command
sudo mongod --dbpath /data/db --repair
then it gives error
sudo: mongod: command not found
Can i ask that if my below command is wrong as i am using the stopped container
root#ip-172-31-6-252:~# sudo docker run -it -p 28001:27017 --name cpx.db mongo:latest mongod --dbpath /data/db --repair
Then if i removed the container and running this command then why this command is not executing and giving conflict error?
EDIT:
Based on recent reply and explanation i had updated my command as below just check it and let me know if there is any correction from your side
sudo docker run -it -p 28000:27017 --name cpx.db1 -v /home/ubuntu/data/cpx.db:/data/db -d mongo:latest mongod --dbpath /data/db --repair
My new process will be as below:
1) go to the running container and stop the mongodb and this will automatically stop the running container
2) run the updated repair command as below
sudo docker run -it -p 28000:27017 --name cpx.db1 -v /home/ubuntu/data/cpx.db:/data/db -d mongo:latest mongod --dbpath /data/db --repair
This command will create a new container named as "cpx.db1" and it will use volume to mount the db and run repair command
3) I'll remove this new container "cpx.db1" as i want to use the old one.
Let me know if i am wrong
Thanks a lot in advance.
Thanks
EDIT:
I run the command and i think it worked as it doesn't give any error but it executed very fast so i am confused, i am hereby stating my commands and output for your reference
I entered in db container
docker exec -it cpx.db /bin/bash
I run shutdown command for mongodb
mongod --shutdown
This was the output (as only process was running in container so after killing this one process i was out of the container)
killing process with pid: 1
FATA[0015] Error response from daemon: Container bd910137a3957c79b304dbbbd221317c909e6779de01ed6f780857e3914c577c is not running: Exited (0) Less than a second ago
Then i run the repair command as below
sudo docker run -it -p 28000:27017 --name cpx.db1 -v /home/ubuntu/data/cpx.db:/data/db -d mongo:latest mongod --dbpath /data/db --repair
This was the output
d6b61222c7145f178e95974c87f95cb06fc8aa5c0c1adc929050ca172ab5f73f
Then i start the old container
docker start cpx.db
And db get started
There was no error but i am confused that whether repair command run successfully or not? Can you check my edited post and let me know your views .
Your current problem :
sudo docker run -it -p 28001:27017 --name cpx.db mongo:latest mongod --dbpath /data/db --repair
Here is the problem.
You're not actually reusing the same container but instanciating a new one. Hence the conflict since you're trying to give to a new container an already taken name.
The container you previously stopped is still stopped, and you don't use it with this command line.
This command line also sums up your problem : you don't understand the difference between images and containers. You're trying to manipulate an image where you should actually manipulate a container (the one you stopped).
What you could do :
As far as I know, it is not possible to restart a container with a different process that the one initially used as entrypoint (If I'm wrong I hope someone else will write an answer to explain how to do so).
But first be aware that storing a whole database in a container is a bad design since you can't access it easily, and you lose it at the container removing.
How you started your container isn't clear to me, but if you didn't do so you should store your database in a mounted volume.
This way your database is persistent, you can remove or stop your container (or even not) and still have access to your database (even from the host for instance).
If you use volumes you can stop your container, execute your repair operation from your host -or from another container if you need the same environment- and just then restarting your first container should be enough.
To use volumes :
here is a short example of the volume usage :
docker run -ti -P -v /host/path:/container/path image sh
This way you run a shell and the /host/path directory from your host will be mounted on the /container/path location inside your container : A change in the one (from host or container) appears in the other.
There are more informations in the link I gave.
Containers vs. images, a nuance important to understand :
You seem to be mistaking images and containers (containers are used to run processes), and you really need to understand the difference.
With docker, an image is what you instanciate your containers from.
You can have several containers instanciated from the same image. If an image was a baking tin, then a container would be a cake.
You probably don't have to remove an image but a running container (assuming you have a conflict because you try to run a container using a port already used by an other running container).
How to remove a container :
To list the containers :
docker ps -a (-a permits to list stopped containers as well).
Once you get the container's id, you can pass it to the docker stop command and then remove the stopped container with the docker rm command (You can use the container's name as well).
Removing containers (docker rm) and removing images (docker rmi) are two whole different things.
EDIT :
1.
sudo docker mongod --dbpath /data/db --repair
mongod is not a docker command. (run, build, ps, etc. are on the other hand).
2.
sudo mongod --dbpath /data/db --repair
Here, you don't even use docker. You simply try to run mongod directly on your host.
3.
sudo docker run -it -p 28001:27017 --name cpx.db mongo:latest mongod --dbpath /data/db --repair
From the manual :
docker run :
Run a command in a new container
So you're not reusing the stopped container, just instantiating a new one.
Keep in mind that REMOVING and STOPPING containers aren't the same.
Assuming you already used volumes to store your database files in first place your host, just :
Stop the container.
Launch a new container with a different name to proceed to your repair operation (still use volumes).
This container will exit at the end of the process, you may remove it.
Restart the container from (1), or even launch a new one (you'll need to delete the old one if you want to reuse the same name in such case, it's probably better to do so if you want to use a fresh one).
Also keep in mind that if you didn't use volumes in first place, the database content is probably not directly accessible from your host filesystem (it's contained in your container, so it's not persistent).
If so, the simplest way is probably to create a new database that would be stored on your host so you can have persistent and easily accessible data.
If you do so, use volumes to access this database (the one on your host) from within your container.

Docker: Mongo exits on run

Using:
https://registry.hub.docker.com/_/mongo/
I did this to pull in all tags:
docker pull mongo
Then, when I try to run it with
docker run -v /data:/data --name mongodb -p 4000:27017 mongo:2.6.6
The status shows
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5959d3f79243 mongo:2.6.6 "/entrypoint.sh mong 4 seconds ago Exited (1) 3 seconds ago mongodb
Logs show:
numactl: This system does not support NUMA policy
How do I keep mongo running while using docker? I am using Docker 1.4.1 on OSX (boot2docker).
Indeed, the boot2docker VM doesn't support NUMA, and the current Dockerfile executes mongod through numactl. A possible workaround:
$ docker run -v /data:/data --name mongodb -p 4000:27017 --entrypoint=mongod mongo:2.6.6
This uses --entrypoint to override the image defined ENTRYPOINT and execute mongod directly.