Last active
April 15, 2024 19:35
-
-
Save mmastoras/5c27ac3321e52e783e4af46d02508f8a to your computer and use it in GitHub Desktop.
Docker Commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run bash in a specific container image | |
docker run -it <image> /bin/bash | |
# run bash and mount a local volume into a specific contaimer image | |
docker run -it -v $(pwd):/pki-tools/pki dprails/pki-tools /bin/bash | |
# run a x86 docker image on M1 mac | |
docker run -it --platform linux/amd64 -v $(pwd):/pki-tools/pki dprails/pki-tools /bin/bash | |
# build on m1 mac | |
docker build --platform linux/amd64 -t <label> . | |
# run a specific container in privileged mode | |
docker run --privileged -it <image> /bin/bash | |
# run a specific container passing environment variable | |
docker run -e ZK_HOST=localhost:2121 -it <image> /bin/bash | |
# attach to running container | |
docker exec -it <container> /bin/bash | |
# override entrypint and command | |
docker run -it --entrypoint=/bin/bash $IMAGE -i | |
# build an image using Dockefile | |
docker build -t <image name> . | |
# build an image with an argument | |
docker build -t <image name> deployment/. --build-arg GITHUB_TOKEN=$GITHUB_TOKEN | |
# docker pushing | |
docker login <repo url> | |
docker tag <image tag or id> <docker registry>/<image name>:<version> | |
docker push <docker registry>/<image name>:<version> | |
# specify a docker file other then Dockerfile when build an image | |
docker build -t concourse-chef-repo -f Dockerfile-ci . | |
# port forward 8080 on host to containers port 80 | |
docker run -p 8080:80 <image> | |
# port forward 8080 on custom ip to containers port 80 | |
docker run -p 10.0.0.3:8080:80 <image> | |
# stop running containers | |
docker stop $(docker ps -a -q) | |
# delete all stopped containers | |
docker rm $(docker ps -a -q) | |
# remove all docker images | |
docker rmi $(docker images -q) | |
# tag an image | |
docker tag <image> <new tag> | |
$ tag by tag | |
docker tag <old tag> <new tag> | |
# inspect running container | |
$ docker inspect <container id> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment