Set Environment Settings:
- DOCKER_CERT_PATH=C:\Users\jini\.docker\machine\certs
- DOCKER_HOST=tcp://192.168.99.100:2376
- DOCKER_TLS_VERIFY=1
- DOCKER_TOOLBOX_INSTALL_PATH= C:\Program Files\Docker Toolbox
Docker Lifecycle:
docker runcreates a container.docker stopstops it.docker startwill start it again.docker restartrestarts a container.docker rmdeletes a container.docker killsends a SIGKILL to a container.docker attachwill connect to a running container.docker waitblocks until container stops.
docker start then docker attach to get in. If you want to poke around in an image,
docker run -t -i to open a tty.Docker Info:
docker ps-a shows running and stopped containers.docker inspectlooks at all the info on a container (including IP address).docker logsgets logs from container.docker eventsgets events from container.docker portshows public facing port of container.docker topshows running processes in container.docker diffshows changed files in the container’s FS.
Docker Images/Container Lifecycle:
docker imagesshows all images.docker importcreates an image from a tarball.docker buildcreates image from Dockerfile.docker commitcreates image from a container.docker rmiremoves an image.docker insertinserts a file from URL into image. (kind of odd, you’d think images would be immutable after create)docker loadloads an image from a tar archive as STDIN, including images and tags (as of 0.7).docker savesaves an image to a tar archive stream to STDOUT with all parent layers, tags & versions (as of 0.7).
Info
docker historyshows history of image.docker tagtags an image to a name (local or registry).
Docker Compose
Define and run multi-container applications with Docker.docker-compose --helpcreate docker-compose.yml
version: '3'
services:
eureka:
restart: always
build: ./micro1-eureka-server
ports:
- "8761:8761"docker-compose stop
docker-compose rm -f
docker-compose build
docker-compose up -d
docker-compose start
docker-compose psScaling containers running a given service
docker-compose scale eureka=3Healing, i.e., re-running containers that have stopped
docker-compose up --no-recreate
Docker Hub
Docker.io hosts its own index to a central registry which contains a large number of repositories.docker loginto login to a registry.docker searchsearches registry for image.docker pullpulls an image from registry to local machine.docker pushpushes an image to the registry from local machine.
Dockerfile
Instructions
- .dockerignore
- FROM Sets the Base Image for subsequent instructions.
- MAINTAINER (deprecated - use LABEL instead)
- RUN execute any commands in a new layer on top of the current image
- CMD provide defaults for an executing container.
- EXPOSE informs Docker that the container listens on the specified network ports at runtime.
- ENV sets environment variable.
- ADD copies new files, directories or remote file to container. Invalidates caches.
Avoid ADD and use COPY instead. - COPY copies new files or directories to container. By default this copies as root regardless of the USER/WORKDIR settings. Use --chown=
: to give ownership to another user/group. (Same for ADD.) - ENTRYPOINT configures a container that will run as an executable.
- VOLUME creates a mount point for externally mounted volumes or other containers.
- USER sets the user name for following RUN / CMD / ENTRYPOINT commands.
- WORKDIR sets the working directory.
- ARG defines a build-time variable.
- ONBUILD adds a trigger instruction when the image is used as the base for another build.
- STOPSIGNAL sets the system call signal that will be sent to the container to exit.
- LABEL apply key/value metadata to your images, containers, or daemons.
Tutorial: Flux7’s Dockerfile Tutorial
Examples: Examples
Best Practices: Best to look at http://github.com/wsargent/docker-devenv and the best practices / take 2 for more details.
Volumes:
Docker volumes are free-floating filesystems. They don’t have to be connected to a particular container.
Volumes are useful in situations where you can’t use links (which are TCP/IP only). For instance, if you need to have two docker instances communicate by leaving stuff on the filesystem.
You can mount them in several docker containers at once, using docker run -volume-from
Get Environment Settings
docker run --rm ubuntu env
Delete old containers
docker ps -a | grep 'weeks ago' | awk '{print $1}' | xargs docker rm
Delete stopped containers
docker rm `docker ps -a -q`
Show image dependencies
docker images -viz | dot -Tpng -o docker.png
Original
https://github.com/wsargent/docker-cheat-sheet/blob/master/README.md
