By mrmardis93
I am starting up MongoDB in a docker container running in an AWS EC2 instance. By company policy, the instance cannot connect to the internet, so I have created a custom Amazon Machine Image that has docker and two images of mongo (3.4 and latest as of the second-to-last week of October 2020). Docker seems to be installed and working fine when I bring up a new EC2 instance, but whenever I run
docker run -d -p 27017:27017 -v bigid-mongo-data:/data/db --name bigid-mongo mongo:3.4
I get the following line in the log
2020-11-02T16:14:55.138+0000 E NETWORK [initandlisten] listen(): bind() failed Permission denied for socket: /tmp/mongodb-27017.sock 2020-11-02T16:14:55.138+0000 E NETWORK [initandlisten] Failed to set up sockets during startup. 2020-11-02T16:14:55.138+0000 E STORAGE [initandlisten] Failed to set up listener: InternalError: Failed to set up sockets
which is followed by exit code 48.
Similarly, when I run
docker run -d -p 27017:27017 -v bigid-mongo-data:/data/db --name bigid-mongo mongo
to use the latest image, I see
{“t”:{“$date”:“2020-11-02T16:43:19.058+00:00”},“s”:“E”, “c”:“STORAGE”, “id”:20568, “ctx”:“initandlisten”,“msg”:“Error setting up listener”,“attr”:{“error”:{“code”:9001,“codeName”:“SocketException”,“errmsg”:“Permission denied”}}}
instead.
Docker works when I use the hello-world image that I pulled and I have already tried changing the permissions of /tmp using
chmod 1777 /tmp
so I am not sure what further steps to take to resolve this issue.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there @mrmardis93,
I could suggest changing the owner of the socket to the MongoDB user:
- sudo chown mongodb:mongodb /tmp/mongodb-27017.sock
Let me know how it goes! Regards, Bobby
(Starting a new chain because I cannot reply to the old one.)
Thank you for the help, @bobbyiliev!
I am still unsure about what is causing the problem, but I am going to create a new Custom AMI. An instance using a previous AMI worked one time and then had the same error, so I hope that another new AMI can fix this.
I will report back here if it is successful or ask a new question if I encounter a different problem.
Best, Mr. M
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.
