Docker
- docker – Docker image and container command line interface
- docker-container – Manage containers
- docker-image – Manage images
- docker-network – Manage networks
- docker-system – Manage Docker
- docker-volume – Manage volumes
- docker-cp – Copy files/folders between a container and the local filesystem
- docker-exec – Run a command in a running container
- docker-logs – Fetch the logs of a container
- docker-rm – Remove one or more containers
- docker-run – Run a command in a new container
- docker-start – Start one or more stopped containers
- docker-stop – Stop one or more running containers
- docker-compose
- Unsorted
docker – Docker image and container command line interface
https://docs.docker.com/engine/reference/commandline/docker/
https://docs.docker.com/engine/reference/commandline/cli/
Management Commands:
builder Manage builds
config Manage Docker configs
container Manage containers
context Manage contexts
engine Manage the docker engine
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
docker-container – Manage containers
https://docs.docker.com/engine/reference/commandline/container/
docker container inspect | Display detailed information on one or more containers |
docker container ls | List containers |
docker container inspect 802264e0b5b5
docker-image – Manage images
https://docs.docker.com/engine/reference/commandline/image/
docker image ls | List images |
docker image prune | Remove unused images |
docker image rm | Remove one or more images |
docker image history | Show the history of an image |
docker image ls
docker image rm IMAGE_ID
docker image history getting-started
Pull all new images
docker images --format "{{.Repository}}:{{.Tag}}"
docker images --format "{{.Repository}}:{{.Tag}}" | xargs -L1 docker pull
Thx to https://dev.to/imjoseangel
docker-network – Manage networks
https://docs.docker.com/engine/reference/commandline/network/
docker network connect | Connect a container to a network |
docker network create | Create a network |
docker network disconnect | Disconnect a container from a network |
docker network inspect | Display detailed information on one or more networks |
docker network ls | List networks |
docker network prune | Remove all unused networks |
docker network rm | Remove one or more networks |
docker network create todo-app
docker-system – Manage Docker
https://docs.docker.com/engine/reference/commandline/system/
docker system df | Show docker disk usage |
docker system events | Get real time events from the server |
docker system info | Display system-wide information |
docker system prune | Remove unused data |
Prune everything
docker system prune
docker-volume – Manage volumes
https://docs.docker.com/engine/reference/commandline/volume/
docker volume create | Create a volume |
docker volume inspect | Display detailed information on one or more volumes |
docker volume ls | List volumes |
docker volume prune | Remove all unused local volumes |
docker volume rm | Remove one or more volumes |
docker volume create todo-db
docker volume inspect todo-db
docker-cp – Copy files/folders between a container and the local filesystem
https://docs.docker.com/engine/reference/commandline/cp/
docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|- docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH
docker cp tmp1:/etc/nginx ./config
docker-exec – Run a command in a running container
--interactive , -i | Keep STDIN open even if not attached |
--tty , -t | Allocate a pseudo-TTY |
Enter a container (container ID given by docker ps
):
docker exec -it 659eb156db55 /bin/bash
docker exec 985cd3b9eae4 more /data.txt
Manage MySQL in a container:
docker exec -it a535a22b59f2 mysql --user=allowed_user -p
Test and reload configuration of nginx in container fc499fea8938:
docker exec fc499fea8938 nginx -t
docker exec fc499fea8938 nginx -s reload
docker-logs – Fetch the logs of a container
docker logs 2dc4059b4ade
docker logs -f ed8d574e096b
docker-rm – Remove one or more containers
Stop and remove container ID 35ed911da1ec
# docker rm -f 35ed911da1ec
Remove all containers:
# docker rm $(docker ps -aq)
docker-run – Run a command in a new container
https://docs.docker.com/engine/reference/commandline/run/
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
--interactive , -i | Keep STDIN open even if not attached |
--tty , -t | Allocate a pseudo-TTY |
--rm | Automatically remove the container when it exits |
--detach , -d | Run container in background and print container ID |
--publish , -p | Publish a container’s port(s) to the host |
--name="" | Assign a name to the container |
--volume , -v | Bind mount a volume |
--network | Connect a container to a network |
--network-alias | Add network-scoped alias for the container |
Run a container:
docker run -d -p 80:80 docker/getting-started
- -d – run the container in detached mode (in the background)
- -p 80:80 – map port 80 of the host to port 80 in the container
- docker/getting-started – the image to use
docker run --rm -it ubuntu /bin/bash
run a container based on the image ubuntu interactively and start /bin/bash in it.
docker run -dp 3000:3000 -v "$(pwd):/app" node:12-alpine
With a bind mount
docker-start – Start one or more stopped containers
docker start c26bbca70a75
docker-stop – Stop one or more running containers
docker start c26bbca70a75
Stop all containers
docker stop $(docker ps -q)
docker-compose
https://docs.docker.com/compose/reference/
https://docs.docker.com/compose/compose-file/
Commands:
build Build or rebuild services
config Validate and view the Compose file
create Create services
down Stop and remove containers, networks, images, and volumes
events Receive real time events from containers
exec Execute a command in a running container
help Get help on a command
images List images
kill Kill containers
logs View output from containers
pause Pause services
port Print the public port for a port binding
ps List containers
pull Pull service images
push Push service images
restart Restart services
rm Remove stopped containers
run Run a one-off command
scale Set number of containers for a service
start Start services
stop Stop services
top Display the running processes
unpause Unpause services
up Create and start containers
version Show version information and quit
-d Detached mode. Run container in the background, print new container name.
Pull the latest images
docker-compose pull
docker-compose up -d
Watch the logs
docker-compose logs -f
docker-compose logs -f app
Remove the container
docker-compose down
docker-compose down --volumes
Unsorted
Where are my container files ?
$ docker info | grep Root
Docker Root Dir: /var/lib/docker
$ sudo ls -la
[...]
drwx-----x 13 root root 4096 Sep 13 10:55 volumes
/var/lib/docker/volumes/mycontainer/_data/
Difference between load and import
Restart policy
https://docs.docker.com/config/containers/start-containers-automatically/
Random
docker ps --all
docker stop d40214ea1a9d
docker rm CONTAINER_ID
docker system prune --all
To avoid weird “connection refused” errors, you have to put 8.8.8.8
in your DNS servers (I don’t exactly know why… >_<).
leopardb@cephadmin:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: dial tcp 18.213.137.78:443: connect: connection refused.
See 'docker run --help'.