You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sudo usermod -aG docker $USER` # add your user to the docker group
docker run -it <IMAGE:TAG> /bin/bash # run container in interactive mode and open a bash shell
docker run -d <IMAGE:TAG> # run container in detach mode
Commands
docker build . # Build an image from path . (where dockerfile is located)
docker tag <IMAGE_ID> <TAG> # Tag image by id
docker images -a # list all images
docker container ls # list running containers
docker container ls -a # list all containers
docker ps -a # list all containers
docker ps -a -q
docker ps -a --format="table {{.Names}}\t{{.Image}}\t{{.Ports}}" # NAMES IMAGE PORTS
docker ps -a | grep "pattern" # list containers base on a pattern
docker ps -a -f status=exited # list containers in a exited status
docker stop $(docker ps -a -q) # stop all containers
docker rm <CONTAINER_ID> # remove container by id
docker rm $(docker ps -a -q) # remove all containers
docker rmi <IMAGE_ID> # remove image by id
docker rmi $(docker images -a -q) # remove all images
docker images | grep "pattern" | awk '{print $1}' | xargs docker rm # remove images base on a pattern
docker ps -a | grep "pattern" | awk '{print $3}' | xargs docker rmi # remove containers base on a pattern
docker rm $(docker ps -a -f status=exited -q) # remove images in a exited status
docker exec -it <CONTAINER NAME> bash # this will create a new Bash session in the container
docker container exec <CONTAINER NAME> poweshell <COMMANDS> # execute comands with powershell windows containers
docker container ls -lq # get container ID of last container
docker container logs $(docker container ls -lq) # show output of last container
docker container diff $(docker container ls -lq) # show the differences between the container and the image
docker container prune # remove all stopped containers
docker system df # check sizes
docker system prune # cleanup your host system
docker network inspect bridge
docker network ls # List all container networks
Networking connect containers
docker container run -d -P --name <CONTAINER NAME> <IMAGE:TAG>
DOCKER COMPOSE
docker-compose up # run all containers
docker-compose up -d # run all containers in the background
docker-compose ps # check which containers are running
docker-compose logs -t client # check the output of the client in its logs
# escape=`
FROM chocolateyfest/iis
COPY iisstart.htm C:\inetpub\wwwroot
Use PowerShell - The default shell in Windows containers is cmd.exe
# escape=`
FROM mcr.microsoft.com/windows/servercore:ltsc2019
RUN powershell -Command Invoke-WebRequest 'http://foo.com/bar.zip' `
-OutFile 'bar.zip' -UseBasicParsing
RUN powershell -Command Expand-Archive bar.zip -DestinationPath C:\
Switch to PowerShell:
Use the SHELL instruction to set PowerShell as default shell,
so you don't have to write powershell -Command in each RUN instruction.
Use $ErrorActionPreference = 'Stop' to abort on first error.
Use $ProgressPreference = 'SilentlyContinue' to improve download speed.