skip to Main Content

I’m trying to run MongoDB in docker on my windows 11 pro pc and I keep getting an error that isn’t very helpful. The command is long/extensive to me and this is my 1st time working with docker or mongo on my pc. Can anyone help me with getting this command to run? I’ve copied and pasted the command from a file as well as I’ve typed it in manually.
enter image description here

here is the command:

docker run -it -d --name mongo-container 
-p 27017:27017 --network MyDockerNetwork 
--restart always 
-v mongodb_data_container:/data/db 
mongo:latest

I typed the command in manually, as well as copied and pasted it in. I expected to have MongoDB installed in docker after executing the command.

2

Answers


  1. First, if the network "MyDockerNetwork" doesn’t exist, you need to create it with this command:

    docker network create MyDockerNetwork
    

    As well as the volume:

    docker volume create mongodb_data_container
    

    And then run the command:

    docker run -d --name mongo-container 
    -p 27017:27017 --network MyDockerNetwork 
    --restart always 
    -v mongodb_data_container:/data/db 
    mongo:latest
    
    Login or Signup to reply.
  2. You’re using a backslash as a line-continuation character with Widows Command Prompt cmd. That only works for Unix/Linux/Mac shells or Git Bash, etc. on Windows.

    Use the caret ^ character instead. Shift + 6 on most keyboards. More details in this answer.

    docker run -it -d --name mongo-container ^
    -p 27017:27017 --network MyDockerNetwork ^
    --restart always ^
    -v mongodb_data_container:/data/db ^
    mongo:latest
    

    Output shows ‘More?’ on each continued line until the last:

    C:Users...>docker run -it -d --name mongo-container ^
    More? -p 27017:27017 --network MyDockerNetwork ^
    More? --restart always ^
    More? -v mongodb_data_container:/data/db ^
    More? mongo:latest
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search