Docker - keshavbaweja-git/guides GitHub Wiki
# Default Entrypoint
/bin/sh -c
# Default Entrypoint + Command
sudo docker run -ti <image> <cmd>
# Docker executes
/bin/sh -c <cmd>
# Specified Entrypoint + Command
# Specify entrypoint using ENTRYPOINT directive in Dockerfile
# Specify entyrpoint using --entrypoint option to run
sudo docker run --entrypoint sh <image> <cmd>
# Specify Dockerfile to build
docker build -f <path-to-Dockerfile> -t <tag> .
# Manage docker as a non root user
sudo groupadd docker` <br> `sudo usermod -aG docker $USER
# Test Docker installation
docker run hello-world
## Delete all images
sudo docker rmi $(sudo docker images -q)
## List all images
sudo docker images
## Create an image from Dockerfile in current directory
sudo docker build -t <tag> .
## Push an image
sudo docker push <docker_username>/<repository_name>:<tag>
Description | Command |
---|---|
Create container from an image |
docker run \ -p <outside_port>:<inside_port> \ <image_name>
|
Create container in detached mode from an image |
docker run \ -d \ -p <outside_port>:<inside_port> \ <image_name>
|
Launch bash inside image | docker run -it <image> /bin/bash |
List running containers | docker container ls |
List all containers | docker container ls --all |
Format docker ps output | docker ps --format "table {{.ID}}\t{{.Command}}\t{{.Image}}" |
List container logs | docker logs <container_id> |
Stop a running container gracefully | docker container stop <container_id> |
Force shutdown of a running container | docker container kill <container_id> |
Remove a container from this machine | docker container rm <container_id> |
Remove all container from this machine | docker container rm $(docker container ls -a -q) |
Description | Command |
---|---|
Find container id | docker ps |
Launch bash inside container | docker exec -it <container_id> /bin/bash |
Exit container | ctrl+d |
Description | Command |
---|---|
Create volume | docker create volume <volume_name> |
List volumes | docker volume ls |
Inspect volume details | docker volume inspect <volume_name> |
Launch a container with a volume |
docker run \ -d -it \ --name <container_name> \ --mount source=<volume_name>,target=/app \ <image_name>
|
Remove unused volumes | docker volume prune |
Docker | Kubernetes | Description |
---|---|---|
entrypoint | cmd | Command array |
cmd | args | Args array |