A collection of personal and technical notes.
Build multiple images simultaneously.
docker build -t <dockerhub_username>/<image_name>:0.0.0 -t <dockerhub_username>/<image_name>:latest .
Build a new Docker image with a Dockerfile.
docker build -t <dockerhub_username>/<app_name>:<version> .
docker build -f <dockerfile> .
List all of the running containers on a host machine.
docker container ls
Rename an existing <container>
to <new_name>
.
docker container rename <container> <new_name>
List all of the available Docker context on a host machine.
docker context ls
Check the current version of Docker compose installed.
docker compose version
Run and/or build a docker-compose.yml
file.
docker compose up
docker compose up --build
docker compose stop
docker compose down
Restart Policies:
docker compose ps
Executes a one-off <bash_command>
in the container.
docker exec <container_id> <bash_command>
Start a shell session within the container.
docker exec -it <container_id> /bin/sh
Remove a local copy of an image.
docker image rm <dockerhub_username>/<image_name>:<tag>
List all of the available images on a host machine.
docker images
# Or,
docker image ls
This stops the container by issuing a SIGKILL
signal to the container.
docker kill <container_id>
Display all the container logs.
docker logs <container_id>
Create a new custom bridge network.
docker network create <network_name>
List custom bridge networks.
docker network ls
List all running containers.
docker ps
List all running/stopped containers.
docker ps -a
-a
or --all
.
Remove a specific Docker container.
docker rm <container_id>
Run a Redis server.
docker run --name redis-server -d -p 6379:6379 redis
Download/execute the hello-world
Docker image.
docker run hello-world
Run a MongoDB server as <container>
with exposed port using the
mongo:4.2.23
image.
docker run --name <container_name> -d -p 27017:27017 mongo:4.2.23
Note:
-d
run container in background and print container ID.p <host_port>:<container_port>
port-forwarding between the host machine and container.<image_name>:<tag>
mongo:4.2.23 is the image_name:tag downloaded.docker run -d -p 3001:2368 -v ghost-vol:/var/lib/ghost/content -e NODE_ENV=development -e URL=http://localhost:3001 ghost
Note:
-v ghost-vol:/var/lib/ghost/content
mounts the ghost-vol
volume to the /var/lib/ghost/content
directory for persistent data.-e NODE_ENV=development
and -e URL=http://localhost:3001
are environment variables.docker run -d --network none docker/gettting-started
docker exec <container_id> ping google.com -W 2 # returns an error
# ping: bad address
Note:
--network none
disable network connection of the container.Downloads an image from Dockerhub.
docker pull <image_name>
docker pull <dockerhub_username>/<image_name>:<tag>
Push multiple images to Docker Hub simultaneously.
docker push <dockerhub_username>/<image_name> --all-tags
Push the image to Docker Hub.
docker push <dockerhub_username>/<image_name>:<tag>
Run a previously stopped container.
docker start <container_name>
This command stops a running container by issuing a SIGTERM
signal to the
container.
docker stop <container_id>
Stop all running processes.
docker stop $(docker ps -q)
Remove all stopped containers, build cache, networks, and volumes.
docker system prune
# or
docker system prune -a
Check the details of the Docker tools installed in your machine.
docker version
Check the current version of Docker engine installed.
docker --version
Create a new storage volume.
docker volume create <volume_name>
List all of the existing storage volume.
docker volume ls
Show the details of an existing storage volume.
docker volume inspect <volume_name>