This content originally appeared on DEV Community and was authored by DEV Community
I often find myself looking up commands or forgetting what I did for a simple task. Thought it would be a good opportunity to compile all the Docker commands I am using on a regular basis for developing applications with Docker. Hoping to crowdsource this, so let me know in the comments below!
DOCKER MACHINE
List all Docker engines:
docker-machine ls
Create a Docker engine:
docker-machine create --driver virtualbox default
Set environment variables for Docker engine:
docker-machine env default
eval $(docker-machine env default)
Start a Docker engine:
docker-machine start default
Stop a Docker engine:
docker-machine stop default
Retrieve IP address for running Docker engine:
docker-machine ip default
DOCKER IMAGES
List Docker images:
docker images
Remove Docker image:
docker rmi <image_id>
docker image rm <image_id>
Create Docker image (requirement: Dockerfile):
docker build -t <dockerhub_username>/<custom_docker_image_name> .
DOCKER CONTAINERS
List Docker containers:
docker ps
docker container ls -a
Stop and remove Docker container:
docker stop <container_id>
docker rm <container_id>
Remove all stopped Docker containers:
docker container prune
Create Docker container (requirement: Docker image):
docker run --name <custom_container_name> -p <new_port>:<defined_port> -d <dockerhub_username>/<custom_docker_image_name>
DOCKER COMPOSE
If development, build, run and keep running (e.g. service_id equals dev):
docker-compose build <service_id>
docker-compose up <service_id>
If testing, build and run once (e.g. service_id equals test):
docker-compose build <service_id>
docker-compose run --rm <service_id>
This content originally appeared on DEV Community and was authored by DEV Community
DEV Community | Sciencx (2021-08-26T19:24:11+00:00) Docker Cheatsheet. Retrieved from https://www.scien.cx/2021/08/26/docker-cheatsheet-3/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.