A collection of all the Docker commands I am using on a regular basis for developing applications with Docker.
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 defaulteval $(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 psdocker 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>