This repository is trending on Github since some days now. Watch it, we will add many updates in the future.
Thank you for your support.
Check the website.
Read this in other languages: English, Russian.
Table of Contents
Installation
Linux
For more information, see here
curl -sSL https://get.docker.com/ | shMac
For more information, see here
Use this link to download the dmg.
https://download.docker.com/mac/stable/Docker.dmgWindows
For more information, see here
Use the msi installer:
https://download.docker.com/win/stable/InstallDocker.msiDocker Registries & Repositories
Login to a Registry
docker logindocker login localhost:8080Logout from a Registry.
docker logoutdocker logout localhost:8080Searching an Image
docker search nginxdocker search --filter stars=3 --no-trunc nginxPulling an Image
docker image pull nginxdocker image pull eon01/nginx localhost:5000/myadmin/nginxPushing an Image
docker image push eon01/nginxdocker image push eon01/nginx localhost:5000/myadmin/nginxRunning Containers
Create and Run a Simple Container
Start an ubuntu:latest image
Bind the port
80from the CONTAINER to port3000on the HOSTMount the current directory to
/dataon the CONTAINERNote: on windows you have to change
-v ${PWD}:/datato-v "C:\Data":/data
docker container run --name infinite -it -p 3000:80 -v ${PWD}:/data ubuntu:latestCreating a Container
docker container create -t -i eon01/infinite --name infiniteRunning a Container
docker container run -it --name infinite -d eon01/infiniteRenaming a Container
docker container rename infinite infinityRemoving a Container
docker container rm infiniteUpdating a Container
docker container update --cpu-shares 512 -m 300M infiniteStarting & Stopping Containers
Starting
docker container start nginxStopping
docker container stop nginxRestarting
docker container restart nginxPausing
docker container pause nginx
Unpausing
docker container unpause nginxBlocking a Container
docker container wait nginxSending a SIGKILL
docker container kill nginxSending another signal
docker container kill -s HUP nginxConnecting to an Existing Container
docker container attach nginxGetting Information about Containers
Running Containers
docker container lsdocker container ls -aContainer Logs
docker logs infiniteFollow Container Logs
docker container logs infinite -fInspecting Containers
docker container inspect infinitedocker container inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -q)Containers Events
docker system events infinitePublic Ports
docker container port infiniteRunning Processes
docker container top infiniteContainer Resource Usage
docker container stats infiniteInspecting changes to files or directories on a container’s filesystem
docker container diff infiniteManipulating Images
Listing Images
docker image lsBuilding Images
docker build .docker build github.com/creack/docker-firefoxdocker build - < Dockerfiledocker build - < context.tar.gzdocker build -t eon/infinite .docker build -f myOtherDockerfile .curl example.com/remote/Dockerfile | docker build -f - .Removing an Image
docker image rm nginxLoading a Tarred Repository from a File or the Standard Input Stream
docker image load < ubuntu.tar.gzdocker image load --input ubuntu.tarSave an Image to a Tar Archive
docker image save busybox > ubuntu.tarShowing the History of an Image
docker image historyCreating an Image From a Container
docker container commit nginxTagging an Image
docker image tag nginx eon01/nginxPushing an Image
docker image push eon01/nginxNetworking
Creating Networks
docker network create -d overlay MyOverlayNetworkdocker network create -d bridge MyBridgeNetworkdocker network create -d overlay \
--subnet=192.168.0.0/16 \
--subnet=192.170.0.0/16 \
--gateway=192.168.0.100 \
--gateway=192.170.0.100 \
--ip-range=192.168.1.0/24 \
--aux-address="my-router=192.168.1.5" --aux-address="my-switch=192.168.1.6" \
--aux-address="my-printer=192.170.1.5" --aux-address="my-nas=192.170.1.6" \
MyOverlayNetworkRemoving a Network
docker network rm MyOverlayNetworkListing Networks
docker network lsGetting Information About a Network
docker network inspect MyOverlayNetworkConnecting a Running Container to a Network
docker network connect MyOverlayNetwork nginxConnecting a Container to a Network When it Starts
docker container run -it -d --network=MyOverlayNetwork nginxDisconnecting a Container from a Network
docker network disconnect MyOverlayNetwork nginxExposing Ports
Using Dockerfile, you can expose a port on the container using:
EXPOSE <port_number>You can also map the container port to a host port using:
e.g.
docker run -p $HOST_PORT:$CONTAINER_PORT --name infinite -t infiniteSecurity
Guidelines for building secure Docker images
Prefer minimal base images
Dedicated user on the image as the least privileged user
Sign and verify images to mitigate MITM attacks
Find, fix and monitor for open source vulnerabilities
Don’t leak sensitive information to docker images
Use fixed tags for immutability
Use COPY instead of ADD
Use labels for metadata
Use multi-stage builds for small secure images
Use a linter
More detailed information on Snyk's 10 Docker Image Security Best Practices blog
Cleaning Docker
Removing a Running Container
docker container rm nginxRemoving a Container and its Volume
docker container rm -v nginxRemoving all Exited Containers
docker container rm $(docker container ls -a -f status=exited -q)Removing All Stopped Containers
docker container rm `docker container ls -a -q`Removing a Docker Image
docker image rm nginxRemoving Dangling Images
docker image rm $(docker image ls -f dangling=true -q)Removing all Images
docker image rm $(docker image ls -a -q)Removing all untagged images
docker image rm -f $(docker image ls | grep "^<none>" | awk "{print $3}")Stopping & Removing all Containers
docker container stop $(docker container ls -a -q) && docker container rm $(docker container ls -a -q)Removing Dangling Volumes
docker volume rm $(docker volume ls -f dangling=true -q)Removing all unused (containers, images, networks and volumes)
docker system prune -fClean all
docker system prune -aDocker Swarm
Installing Docker Swarm
curl -ssl https://get.docker.com | bashInitializing the Swarm
docker swarm init --advertise-addr 192.168.10.1Getting a Worker to Join the Swarm
docker swarm join-token workerGetting a Manager to Join the Swarm
docker swarm join-token managerListing Services
docker service lsListing nodes
docker node lsCreating a Service
docker service create --name vote -p 8080:80 instavote/voteListing Swarm Tasks
docker service psScaling a Service
docker service scale vote=3Updating a Service
docker service update --image instavote/vote:movies votedocker service update --force --update-parallelism 1 --update-delay 30s nginxdocker service update --update-parallelism 5--update-delay 2s --image instavote/vote:indent votedocker service update --limit-cpu 2 nginxdocker service update --replicas=5 nginxNotes
This work was first published in Painless Docker Course
评论已关闭