Default
Basic commands
docker image
Build an image from the Dockerfile in the current directory
class="highlight">
1docker image build .
Build an image with repository and tag from a root directory
class="highlight">
1docker image build -t myRepo:myTag /my/root/dir/
List images
class="highlight">
1docker image ls
class="highlight">
1 docker imagesRemove image
class="highlight">
1docker image rm web1
Show detailed information of an image
class="highlight">
1 docker image inspect web1Create a tag image from a source image
class="highlight">
1 docker image tag web1 adr1/web1:latestPush an image to a registry
class="highlight">
1 docker image push adr1/web1:latestdocker container
List running containers
class="highlight">
1docker container ls
List all containers
class="highlight">
1 docker container ls -aRun a command in a new container
class="highlight">
1docker container run -it alpine sh
or docker run -it alpine sh
with interactive terminal
class="highlight">
1docker container run -it web1
with binding to host port
class="highlight">
1 docker container run -it -p5000:5000 web1with binding to a random host port
class="highlight">
1 docker container run -it -p5000 web1with environment variables
class="highlight">
1 docker container run -it -p5000:5000 -e FLASK_APP=app.py -e FLASK_DEBUG=1 web1in the background and detached
class="highlight">
1 docker container run -it -p5000:5000 -d web1with auto-removal of container when it exits
class="highlight">
1 docker container run -it -rm -p5000:5000 web1with a name assigned to the container
class="highlight">
1 docker container run -it --name web1 -p5000:5000 web1with a restart policy on failure
class="highlight">
1 docker container run -it --name web1 --restart on-failure -p5000:5000 web1with a volume mounted
class="highlight">
1 docker container run -it -p 5000:5000 -e FLASK_APP=app.py --rm --name web1 -e FLASK_DEBUG=1 -v $PWD:/app web1Remove a container
class="highlight">
1docker container rm web1
Remove all containers
class="highlight">
1 docker container rm $(docker ps -a -q)Show container detailed information
class="highlight">
1 docker container inspect web1Run a command in a running container
class="highlight">
1 docker container exec -it web1 lswith option -it = interactive, tty
class="highlight">
1 docker container exec -it web1 shset file name permission to user
class="highlight">
1 docker container exec -it --user "$(id -u):$(id -g)" touch hello.txtdocker pull
Pull an image from a registry
class="highlight">
1 docker pull adr1/web1:latestdocker-compose
docker import / export
Export from container to tarball
class="highlight">
1 docker export myContainerId > myImage.tarImport from tarball to repostory
class="highlight">
1 docker import - myRepo < myImage.tardocker save / load
Save repository to tarball
class="highlight">
1docker save -o myImage.tar myRepo
Load tarball to repository
class="highlight">
1 docker load < myImage.tarTrending Tags