Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 26, 2021 07:24 pm GMT

Docker Cheatsheet

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 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>

Original Link: https://dev.to/mrinasugosh/docker-command-cheatsheet-1pe8

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To