Skip to content

Instantly share code, notes, and snippets.

Last active Jun 1, 2021
What would you like to do?
Docker common commands
# ---------------------------------------------------------
# docker file -> text file with commands to create an image
# images -> a read-only memory dump
# container -> running or stopped image with working data
# ---------------------------------------------------------
# see also:
# List all running docker containers
docker ps
# List all docker containers, including the stopped containers
docker ps -a
# Run a new docker container from image, in the current shell
# if you close the shell the container will be stopped
docker run mongo
# Run a new docker container from, in the background
docker run -d mongo
# Map host port to container port and giv environment variable
docker run -p 27017:27017 -e PASSWORD=password mongo
# Starts a existing container
docker start
# Show logs
docker logs b6e69efb94f3
# Stop a docker container, use the container id (see 'docker ps')
docker stop b6e69efb94f3
# List all images
docker images -a
# Remove image
docker rmi b6e69efb94f3
# Build a docker image from docker file in the current directory
docker build -t tagname
# Shell into an image
docker run --rm -it --entrypoint=/bin/bash imageName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment