🎩
wilmerags 🌱
  • Home
  • Social
  • Cloud
    • Aws
  • Stats
  • Code
    • Scrum
    • Ssh
    • Vim
    • Dvc
    • Postgresql
    • Tmux
    • Terraform
    • Web tools
    • Sql
    • Rest api
    • Mongo
    • Docker
    • Octave
    • Elasticsearch
    • Kubernetes
    • Bash
    • Rabbitmq
    • Databases
      • Mongo
      • Elasticsearch
      • Sql
        • Postgresql
    • Devops
      • Terraform
      • Docker
      • Kubernetes
      • Rabbitmq
    • Python
      • Airflow
      • Keras
      • Spark
      • Azure
      • Matplotlib
      • Jupyter
      • Numpy
      • Databases
      • Sklearn
      • Requests
      • Pandas
      • Elasticsearch
      • Tensorflow
    • Git
      • Gitflow
    • R
      • Lpsolve
  • Indie-hacker
  • Macos
  • Interesting
  • Thoughts
    • Health
    • Work
    • Relationships
    • On the need of expressiveness
    • On organizing knowledge
    • On the importance of questions
  • Linux
    • Vim
    • Tmux
  • Webdev
    • Vue
  • Readings
    • Psychology
    • Habits
    • Projects management
    • Quotes
    • Dopamine detox
  • Ai
    • Ml
      • Xgboost
      • Performance evaluation
      • Community detection
      • Cloud_platforms
        • Ai platform
        • Sagemaker
      • Unsupervised_learning
    • Nlp
    • DS
Powered by GitBook
On this page
  1. Code
  2. Devops

Docker

Useful concepts and snippets for using Docker

PreviousTerraformNextKubernetes

Last updated 3 years ago

Was this helpful?

CtrlK
  • Guidelines
  • Recipes

Was this helpful?

Guidelines

  • Always add .dockerignore file.

  • Try to use and exploit multi-stage builds.

Recipes

Installing Docker

sudo apt-get update
curl -sSL https://get.docker.com/ | sh
sudo usermod -aG docker $USER
sudo service docker start

Installing Docker-compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose

Dockerfile With python venv's

FROM python:3.8-slim-buster

ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Install dependencies:
COPY requirements.txt .
RUN pip install -r requirements.txt

# Run the application:
COPY myapp.py .

Remove all exited containers: docker rm $(docker ps -a -f status=exited -q)

Building docker images:

  • https://codefresh.io/docker-tutorial/build-docker-image-dockerfiles/

Remove all images docker rmi $(docker images -a -q)

Remove dangling images

docker image prune

Remove dangling volume

docker volume prune

Kill all system garbage

docker system prune

Run container

docker run --network="host" -p 8080:8080 --name <name-of-the-container> wilmerags/image-name:tag
# network host to make it visible

**Add parameters to docker image build **

docker build --build-arg APP_ENV=DESIRED_ENV -f Dockerfile -t wilmerags/twitter-executor:IMAGE_TAG .
# ...
COPY env/${APP_ENV}/.env /app/
# ...

Tag image for pushing

docker tag 434eb3701cc9 wilmerags/twitter-executor # 434.. is the image ID

Building local image into docker-compose:

  • https://stackoverflow.com/questions/46032392/docker-compose-does-not-allow-to-use-local-images

Resources

  • https://pythonspeed.com/articles/multi-stage-docker-python/

  • https://medium.com/capital-one-tech/multi-stage-builds-and-dockerfile-b5866d9e2f84

  • https://pythonspeed.com/docker/

  • The Rabbit Hole of Using Docker in Automated Tests

  • has a useful blog post on at Dramafever.

  • There's also a best practices from Lyst.

/usr/bin/docker-compose
docker-compose --version
CMD ["python", "myapp.py"]
Bridget Kromhout
running Docker in production
blog post
Building a Development Environment With Docker
Discourse in a Docker Container