Last active
September 13, 2020 10:15
-
-
Save dipaktelangre/018a8b15a3ca65ab7e53e777fc1a73ab to your computer and use it in GitHub Desktop.
MongoDB in docker and Docker commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Pull mongo image | |
| docker pull mongo | |
| # Run container from image mongo in background, publish 50001 host port to 27017 container port | |
| docker run --name mongoserver --restart=always -d -p 50001:27017 mongo | |
| #------------------------- Refrence Commands ---------------------- | |
| # Show docker images | |
| docker images | |
| # Remove docker image | |
| docker rmi image_id | |
| # Pull docker image | |
| docker pull image_name | |
| # Display system-wide information | |
| docker info | |
| #List constainers | |
| docker ps | |
| # List all containers | |
| docker ps -a | |
| # List container with filters - exited | |
| docker ps -a --filter 'exited=0' | |
| # List container with filter name | |
| docker ps --filter "name=nostalgic" | |
| # List container which are running | |
| docker ps --filter status=running | |
| # list all running containers with their labels in a table format | |
| docker ps --format "table {{.ID}}\t{{.Labels}}" | |
| # Remove container | |
| docker rm container_name/container_id | |
| # Run a command in a new container | |
| docker run [OPTIONS] | |
| # Run container with name mongoserver from image mongo intractive shell | |
| docker run -it --name mongoserver mongo bash | |
| # Run container in background and print container ID | |
| docker run -it --name mongoserver -d mongo bash | |
| # Publish a container’s port(s) to the host -p host_port:container_port | |
| docker run --name mongoserver --restart=always -d -p 27017:27017 mongo | |
| # bash into the container | |
| sudo docker exec -i -t mongoserver bash | |
| # stop container | |
| docker stop mongoserver | |
| # start container | |
| docker start mongoserver | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment