Docker
De Linuxmemo.
(Différences entre les versions)
Ligne 53 : | Ligne 53 : | ||
To enter a running container, attach a new shell process to a running container called foo, use: docker exec -it foo /bin/bash. | To enter a running container, attach a new shell process to a running container called foo, use: docker exec -it foo /bin/bash. | ||
- | == | + | ==Images== |
+ | ===Lifecycle=== | ||
+ | docker images shows all images. | ||
+ | docker import creates an image from a tarball. | ||
+ | docker build creates image from Dockerfile. | ||
+ | docker commit creates image from a container, pausing it temporarily if it is running. | ||
+ | docker rmi removes an image. | ||
+ | docker load loads an image from a tar archive as STDIN, including images and tags (as of 0.7). | ||
+ | docker save saves an image to a tar archive stream to STDOUT with all parent layers, tags & versions (as of 0.7). | ||
+ | |||
+ | ===Info=== | ||
+ | docker history shows history of image. | ||
+ | docker tag tags an image to a name (local or registry). | ||
+ | |||
+ | ===Cleaning up=== | ||
+ | docker rmi command to remove specific images, there's a tool called docker-gc that will clean up images that are no longer used by any containers in a safe manner. | ||
+ | |||
+ | ==Networks== | ||
+ | ===Lifecycle=== | ||
+ | docker network create | ||
+ | docker network rm | ||
+ | |||
+ | ===Info=== | ||
+ | docker network ls | ||
+ | docker network inspect | ||
+ | ===Connection=== | ||
+ | docker network connect | ||
+ | docker network disconnect | ||
+ | |||
+ | You can specify a specific IP address for a container: | ||
+ | # create a new bridge network with your subnet and gateway for your ip block | ||
+ | docker network create --subnet 203.0.113.0/24 --gateway 203.0.113.254 iptastic | ||
+ | |||
+ | # run a nginx container with a specific ip in that block | ||
+ | $ docker run --rm -it --net iptastic --ip 203.0.113.2 nginx | ||
+ | |||
+ | # curl the ip from any other place (assuming this is a public ip block duh) | ||
+ | $ curl 203.0.113.2 |
Version du 20 juin 2016 à 09:12
Sommaire |
Install
apt-get install docker.io
via proxy http
https://docs.docker.com/engine/admin/systemd/#http-proxy
sudo mkdir /etc/systemd/system/docker.service.d sudo vim /etc/systemd/system/docker.service.d/http-proxy.conf [Service] Environment="HTTP_PROXY=http://proxy.example.com:80/" "HTTPS_PROXY=https://proxy.example.com:80/" sudo systemctl daemon-reload sudo systemctl show --property=Environment docker sudo systemctl restart docker
Containers
Source: https://github.com/wsargent/docker-cheat-sheet/blob/master/README.md
Lifecycle
docker create creates a container but does not start it. docker rename allows the container to be renamed. docker run creates and starts a container in one operation. docker rm deletes a container. docker update updates a container's resource limits.
Starting and Stopping
docker start starts a container so it is running. docker stop stops a running container. docker restart stops and starts a container. docker pause pauses a running container, "freezing" it in place. docker unpause will unpause a running container. docker wait blocks until running container stops. docker kill sends a SIGKILL to a running container. docker attach will connect to a running container.
Info
docker ps shows running containers. docker logs gets logs from container. (You can use a custom log driver, but logs is only available for json-file and journald in 1.10) docker inspect looks at all the info on a container (including IP address). docker events gets events from container. docker port shows public facing port of container. docker top shows running processes in container. docker stats shows containers' resource usage statistics. docker diff shows changed files in the container's FS.
docker ps -a shows running and stopped containers. docker stats --all shows a running list of containers.
Import / Export
docker cp copies files or folders between a container and the local filesystem.. docker export turns container filesystem into tarball archive stream to STDOUT.
Executing Commands
docker exec to execute a command in container. To enter a running container, attach a new shell process to a running container called foo, use: docker exec -it foo /bin/bash.
Images
Lifecycle
docker images shows all images. docker import creates an image from a tarball. docker build creates image from Dockerfile. docker commit creates image from a container, pausing it temporarily if it is running. docker rmi removes an image. docker load loads an image from a tar archive as STDIN, including images and tags (as of 0.7). docker save saves an image to a tar archive stream to STDOUT with all parent layers, tags & versions (as of 0.7).
Info
docker history shows history of image. docker tag tags an image to a name (local or registry).
Cleaning up
docker rmi command to remove specific images, there's a tool called docker-gc that will clean up images that are no longer used by any containers in a safe manner.
Networks
Lifecycle
docker network create docker network rm
Info
docker network ls docker network inspect
Connection
docker network connect docker network disconnect
You can specify a specific IP address for a container:
# create a new bridge network with your subnet and gateway for your ip block docker network create --subnet 203.0.113.0/24 --gateway 203.0.113.254 iptastic
# run a nginx container with a specific ip in that block $ docker run --rm -it --net iptastic --ip 203.0.113.2 nginx
# curl the ip from any other place (assuming this is a public ip block duh) $ curl 203.0.113.2