How do I mount a host directory as a volume in docker compose

Checkout their documentation From the looks of it you could do the following on your docker-compose.yml volumes: – ./:/app Where ./ is the host directory, and /app is the target directory for the containers. EDIT:Previous documentation source now leads to version history, you’ll have to select the version of compose you’re using and look for … Read more

How to use environment variables in docker-compose?

The DOCKER solution: Docker-compose 1.5+ has enabled variables substitution: https://github.com/docker/compose/releases The latest Docker Compose allows you to access environment variables from your compose file. So you can source your environment variables, then run Compose like so: set -a source .my-env docker-compose up -d For example, assume we have the following .my-env file: POSTGRES_VERSION=14 (or pass … Read more

How to get docker-compose to always re-create containers from fresh images?

docker-compose up –force-recreate is one option, but if you’re using it for CI, I would start the build with docker-compose rm -f to stop and remove the containers and volumes (then follow it with pull and up). This is what I use: docker-compose rm -f docker-compose pull docker-compose up –build -d # Run some tests … Read more

Difference between links and depends_on in docker_compose.yml

This answer is for docker-compose version 2 and it also works on version 3 You can still access the data when you use depends_on. If you look at docker docs Docker Compose and Django, you still can access the database like this: version: ‘2’ services: db: image: postgres web: build: . command: python manage.py runserver … Read more

Docker: How to clear the logs properly for a Docker container?

First the bad answer. From this question there’s a one-liner that you can run: echo “” > $(docker inspect –format=”{{.LogPath}}” <container_name_or_id>) instead of echo, there’s the simpler: : > $(docker inspect –format=”{{.LogPath}}” <container_name_or_id>) or there’s the truncate command: truncate -s 0 $(docker inspect –format=”{{.LogPath}}” <container_name_or_id>) I’m not a big fan of either of those since … Read more

What’s the difference between Docker Compose and Kubernetes?

Containers: Containers are at the core of the other technologies listed here Docker: Docker is a popular implementation of the technology that allows applications to be bundled into a container. docker is a command-line tool to manage images, containers, volumes, and networks Docker Compose Docker Compose is the declarative version of the docker cli It … Read more