Hudson  Kunde

Hudson Kunde

1596335580

Docker Compose Syntax: Volume or Bind Mount?

Docker Compose allows you to configure volumes and bind mounts using a short syntax. A few examples:

./public:/usr/share/nginx/html

/var/lib/postgresql/data

/some/content:/usr/share/nginx/html

~/configs:/etc/configs

postgresql:/var/lib/postgresql/data

Which of these are volumes and which are a bind mounts?

Whenever I had to read a docker-compose.yml file, I had to look up the official documentation or run a quick local experiment to figure out how Docker Compose would mount the directories into the container.

I wrote this article so that next time you read a Docker Compose file, you won’t have to guess anymore. You’ll simply know by looking at the syntax whether a volume or a bind mount is used behind the scenes.

The different variations are essentially three unique forms. I list and explain them in this article below.

Two volumes keys in docker-compose.yml

Before we talk about the different ways to specify volumes, let’s first clarify which volumes key we’re referring to. In docker-compose.yml, the volumes key can appear in two different places.

version: "3.7"

services:
  database:
    # ...
    volumes: # Nested key. Configures volumes for a particular service.

volumes: # Top-level key. Declares volumes which can be referenced from multiple services.
  # ...

In this article, we’ll talk about the nested volumes key. That’s where you configure volumes for a specific service/container such as a database or web server. This configuration has a short (and a long) syntax format.

Short syntax format and its variations

The volume configuration has a short syntax format that is defined as:

[SOURCE:]TARGET[:MODE]

SOURCE can be a named volume or a (relative or absolute) path on the host system. TARGET is an absolute path in the container. MODE is a mount option which can be read-only or read-write. Brackets mean the argument is optional.

This optionality leads to three unique variations you can use to configure a container’s volumes. Docker Compose is smart about recognising which variety is used and whether to use a volume or bind mount.

#docker #syntax #volume #bind mount

What is GEEK

Buddha Community

Docker Compose Syntax: Volume or Bind Mount?
Hudson  Kunde

Hudson Kunde

1596335580

Docker Compose Syntax: Volume or Bind Mount?

Docker Compose allows you to configure volumes and bind mounts using a short syntax. A few examples:

./public:/usr/share/nginx/html

/var/lib/postgresql/data

/some/content:/usr/share/nginx/html

~/configs:/etc/configs

postgresql:/var/lib/postgresql/data

Which of these are volumes and which are a bind mounts?

Whenever I had to read a docker-compose.yml file, I had to look up the official documentation or run a quick local experiment to figure out how Docker Compose would mount the directories into the container.

I wrote this article so that next time you read a Docker Compose file, you won’t have to guess anymore. You’ll simply know by looking at the syntax whether a volume or a bind mount is used behind the scenes.

The different variations are essentially three unique forms. I list and explain them in this article below.

Two volumes keys in docker-compose.yml

Before we talk about the different ways to specify volumes, let’s first clarify which volumes key we’re referring to. In docker-compose.yml, the volumes key can appear in two different places.

version: "3.7"

services:
  database:
    # ...
    volumes: # Nested key. Configures volumes for a particular service.

volumes: # Top-level key. Declares volumes which can be referenced from multiple services.
  # ...

In this article, we’ll talk about the nested volumes key. That’s where you configure volumes for a specific service/container such as a database or web server. This configuration has a short (and a long) syntax format.

Short syntax format and its variations

The volume configuration has a short syntax format that is defined as:

[SOURCE:]TARGET[:MODE]

SOURCE can be a named volume or a (relative or absolute) path on the host system. TARGET is an absolute path in the container. MODE is a mount option which can be read-only or read-write. Brackets mean the argument is optional.

This optionality leads to three unique variations you can use to configure a container’s volumes. Docker Compose is smart about recognising which variety is used and whether to use a volume or bind mount.

#docker #syntax #volume #bind mount

August  Murray

August Murray

1615023900

Docker: Manage Data in Docker -Understanding “Docker Volumes” and “Bind Mounts”

Introduction

By Design, Docker containers don’t hold persistent data. Any data you write inside the docker’s writable layer is no longer available once the container is stopped. It can be difficult to get the data out of the container if another process needs it.

Also, a container’s writable layer is tightly coupled to the host machine where the container is running. You can’t easily move the data somewhere else.

Docker has two options for containers to store files in the host machine, so that the files are persisted even after the container stops: volumes, and bind mounts.

  • Volumes are stored in a part of the host filesystem which is managed by Docker (/var/lib/docker/volumes/ on Linux). Non-Docker processes should not modify this part of the filesystem. Volumes are the best way to persist data in Docker.
  • Bind mounts may be stored anywhere on the host system. They may even be important system files or directories. Non-Docker processes on the Docker host or a Docker container can modify them at any time.

Let’s understand them in detail one by one.

#docker-container #docker #docker-volume #containerization

August  Murray

August Murray

1614993670

Manage Docker Storage & Volumes

Intro to volumes and storage.

TL;DR Overview of how docker storage & volumes work and how to manage them.

In this fourth part of the Dockerventure series, we are going to focus on how docker handles storage, how it manages container file systems, and showcase how we can effectively manage our data with volumes.

Check here for the first 3 parts: Intro DockerDockerfilesUseful Docker commands.

Default Docker File System

By default at creation time, docker creates the directory /var/lib/docker where it stores all its data regarding containers, images, volumes, etc.

When a new container is started, a new **read-write container layer **is added on top of the read-only image layers that were created during the build phase.

This container layer exists only while the container exists and when the container is killed this layer along with all the changes we made on top is lost.

#docker-mount #docker-volume #docker-storage #docker

Iliana  Welch

Iliana Welch

1595249460

Docker Explained: Docker Architecture | Docker Registries

Following the second video about Docker basics, in this video, I explain Docker architecture and explain the different building blocks of the docker engine; docker client, API, Docker Daemon. I also explain what a docker registry is and I finish the video with a demo explaining and illustrating how to use Docker hub

In this video lesson you will learn:

  • What is Docker Host
  • What is Docker Engine
  • Learn about Docker Architecture
  • Learn about Docker client and Docker Daemon
  • Docker Hub and Registries
  • Simple demo to understand using images from registries

#docker #docker hub #docker host #docker engine #docker architecture #api

Iliana  Welch

Iliana Welch

1595294640

O que são Bind Mounts em Docker?

Depois de entendermos melhor sobre Volumes, vamos agora falar sobre um outro tipo chamado de Bind Mount.

Vamos aqui falar sobre a diferença entre esse tipo e o tipo padrão de volumes e como utilizá-lo na prática.

Também vamos falar sobre possíveis utilidades onde esse formato se encaixa melhor.

#docker #volumes #bind mounts