Last active
May 2, 2021 15:49
-
-
Save iahim/b02ded5312a20ab559d8cb7436af1647 to your computer and use it in GitHub Desktop.
This file contains 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
# BEST PRACTICES | |
# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#exclude-with-dockerignore | |
# docker commands I use on a daily basis | |
docker run -d --rm --name myRedis -p 6379:6379/tcp redis | |
# interactive mode | |
docker run -it [IMAGE] | |
# attach to an existing container | |
docker exec -it <container name> /bin/bash | |
# START A CONTAINER | |
docker container start <container name> | |
# build an image (from a different context / Docker file) and tag the image | |
docker build -t pipeline:v1 -f docker/base-image/Dockerfile . | |
# REMOVE DANGLING IMAGES | |
docker rmi $(docker images --filter "dangling=true" -q --no-trunc) | |
# CLEAN dangling images/containers | |
docker system prune | |
# DOCKER TAG | |
docker image tag rhel-httpd:latest registry-host:5000/myadmin/rhel-httpd:latest | |
# DOCKER PUSH | |
docker image push registry-host:5000/myadmin/rhel-httpd:latest | |
# TRUNCATE ALL LOGS | |
truncate -s 0 /var/lib/docker/containers/*/*-json.log | |
# ==================================== | |
# DOCKER VOLUME - for data persistance | |
# ==================================== | |
docker volume help | |
docker volume create redis01 | |
docker volume inspect redis01 | |
# run container using volume: | |
docker run -d --rm --name myRedis -v redis01:/data -p 6379:6379/tcp redis:alpine | |
# ==================================== | |
# DOCKER COMPOSE | |
# ==================================== | |
# https://docs.docker.com/compose/compose-file/ | |
# BUILD | |
docker-compose -p pipe --env-file ./docker/.env.dev build | |
docker-compose -p pipe --env-file ./docker/.env.dev build -f docker/docker-compose.yml | |
# UP | |
docker-compose -p pipe --env-file ./docker/.env.dev up -d | |
# PS | |
docker-compose -p pipe --env-file ./docker/.env.dev ps | |
# attach to an existing service | |
docker-compose -p pipe --env-file ./docker/.env.dev exec serviceName bash | |
# SCALE a service | |
docker-compose -p pipe --env-file ./docker/.env.dev up --scale app=2 | |
docker-compose scale web=2 worker=3 | |
# ==================================== | |
# MEMORY | |
# ==================================== | |
# mem = m|g | |
docker run -it --memory="[memory_limit]" [docker_image] | |
docker run -it --memory="1g" ubuntu | |
sudo docker run -it --memory="1g" --memory-swap="2g" ubuntu | |
# if you don't want to use swap, set the same value for swap as for the memory | |
# --memory-reservation="750m" this is a soft limit and should be less than the --memory hard limit | |
# ==================================== | |
# CPU | |
# ==================================== | |
# give access to one cpu | |
docker run -it --cpus="1.0" ubuntu | |
# specify cycles (default = 1024) | |
docker run -it --cpus-shares="700" ubuntu | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment