Skip to content

Instantly share code, notes, and snippets.

@gustavoapolinario
Last active January 27, 2019 19:51
Show Gist options
  • Save gustavoapolinario/fb471bdb2fdeb49c6ebc915f760fc4b0 to your computer and use it in GitHub Desktop.
Save gustavoapolinario/fb471bdb2fdeb49c6ebc915f760fc4b0 to your computer and use it in GitHub Desktop.
Docker common commands
# Basic Docker run
docker run \
# Share file/directory
-v ./bkp:/bakup
# Remember... use ´touch .bash_history´ before share if file don't exists
-v .bash_history:/root/.bash_history
# Port to share (port in your pc:conatiner port)
-p 3306:3306
# Env Variables
-e VARIABLE="variable_content"
# Image from repository (without repository information, get from docker hub)
IP-REGISTRY:5000/docker-image-name:latest
# Example with entrypoint overload
docker run --rm --entrypoint "/bin/ls" container_name
# List docker containers executing
docker ps
# List docker containers executing and stopped
docker ps -a
# List docker images
docker images
# List docker volumes
docker volumes
# Show HD use
docker system df
# Show modifications of image (with size)
docker history IMAGE_ID
# Execute command with interactive terminal
docker exec -it IMAGE_NAME COMMAND
ex: docker exec -it myapp ls -lah /app
# Go to Container bash
docker exec -it IMAGE_NAME bash
# or
docker exec -it IMAGE_NAME /bin/bash
# Show environment varibles to test
docker exec container bash -c 'echo "$ENV_VAR"'
# Remove everything unnused (CAUTION!!)
docker system prune
docker image prune --all
# Remove all stopped containers (CAUTION!!)
docker ps -a -q | xargs --no-run-if-empty docker rm
# Remove unnused images
docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi
# Remove unnused volumes
docker volume ls -q -f dangling=true | xargs --no-run-if-empty docker volume rm
# IF you have HD problem, verify the dir
/var/lib/docker/devicemapper/
FROM amazonlinux:latest
ARG AURL="https://www.site.com.br/"
ENV URL=$URL
CMD echo $URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment