Last active
January 2, 2018 14:58
-
-
Save anacromaniac/484514141b7a3d901779eaaba2639439 to your computer and use it in GitHub Desktop.
Docker reference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run a command on a OS image | |
docker container run <container> <command> | |
# List running containers, --all lists even those that exited | |
docker container ls [--all] | |
# Run a docker container and access its shell, --rm removes container after exiting | |
docker container run --interactive --tty [--rm] <container> bash | |
# Run a background container | |
docker container run \ | |
--detach \ # <---------------- runs in background | |
--name <name> \ # <---------------- reference name | |
[--publish <container-port>:<host-port>] \ | |
[--mount type=bind,source="$(pwd)",target=<target-folder>] \ # <--------------source = $(pwd) uses curretn folder | |
-e <ENVIRONMENT_VARIABLE>=<environment variable value> \ # <-------Loads environment variable | |
<container> | |
# See the logs inside a container | |
docker container logs <reference-name> | |
# Look at processes running inside container | |
docker container top <reference-name> | |
# Execute a command inside the container | |
docker exec -it <reference-name> <command> | |
# DOCKERFILE | |
-FROM specifies the base image to use as the starting point for this new image you’re creating. For this example we’re starting from nginx:latest. | |
-COPY copies files from the Docker host into the image, at a known location. In this example, COPY is used to copy two files into the image: index.html. and a graphic that will be used on our webpage. | |
-EXPOSE documents which ports the application uses. | |
-CMD specifies what command to run when a container is started from the image. Notice that we can specify the command, as well as run-time arguments. | |
# Build docker image from Dockerfile | |
docker image build --tag <DOCKER-ID>/<name>:<maj-v>.<min-v> . | |
# Remove docker container | |
docker container rm --force <reference-name> | |
# Login to Docker Hub | |
docker login | |
# Push image to Docker Hub | |
docker image push <image> | |
# Init a Docker Swarm | |
docker swarm init --advertise-addr $(hostname -i) | |
# Deploy a stack | |
docker stack deploy --compose-file=<filename>.yml <stack-name> | |
# Check deployed stack | |
docker stack ls | |
# Check services within the stack | |
docker stack services <stack-name> | |
# Check tasks of a given service | |
docker service ps <service> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment