Docker CLI useful command
- vs code plugin for docker is pretty nice.
-
official overview of docker cli commands.
-
docker build . -t crowdsalat/imageName:tag
creates a image based on a Dockerfile and the context/ working directory and subdirectories docker run <image>
starts a container from an image-d
run as daemon-it
runs interactively so you can execute commands in container (-t Allocate a pseudo-tty, -i Keep STDIN open )docker run -it --entrypoint sh crowdsalat/imageName:tag
starts a container and starts a interactive shell.-p 500:1000
maps the port 1000 of the container to the port 500 of the host. Reachable under localhost on the host system.-p 192.168.178.123:1000:500
maps the port 1000 of the container to the port of the host. Reachable under localhost on the host system. Reachable under the IP address of the host system.-v /var/logs/
binds /var/logs inside the container to a unnamed volume on the mount which resides in /var/lib/docker/volumes/-v /var/run/docker.sock:/var/run/docker.sock
containers started inside of this container will be started on the host a not inside the container (sibling not a child). Useful in CI/CD pipelines which uses containers as runners see: https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/-e VAR1=bla -e VAR2=blubb
defines environmental variables in the container—rm
remove container after it is stopped.—name
add name to the container.
docker history --no-trunc <image>
show something similar to the original dockerfiledocker exec -it container_name bash
connects to a running container with the name container_namedocker ps −a
shows all running docker container on a clientdocker image / container / network / volumes / system
- ls
- rm
- inspect
docker system prune
removes:- all stopped containers (
docker container prune
) - all networks not used by at least one container (
docker network prune
) - all dangling images (
docker image prune
) - all dangling build cache
- all stopped containers (
docker network create --driver bridge <bridgeName>
create a new bridge networkdocker volume create <volumeName>
create a new bridge volumedocker cp <containerName>:<pathInConainer> <pathOnHost>
copies data from the container to the host. Helpful if volume were not set up correct
If you pull a image with the latest tag it will first try to download it from docker hub and only if it is not there it will use a local variant.