Need help?

Our experts have had an average response time of 11.7 minutes in August 2021 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

Manage Docker Volumes using Docker Compose

by | Jan 28, 2021

Need to Manage Docker Volumes using Docker Compose? We can help you

Docker Compose is a tool used for defining and running multi-container Docker applications.

This means that we can organize or arrange Docker containers to use them in a better way with the help of Docker Compose.

The main advantage of using Docker Compose is that it works in all environments such as production, staging, development, testing, as well as CI workflows.

Here at Bobcares, we often use Docker Compose to manage Docker Volumes of our customers using Docker.

Today, let’s see how our Support Engineers do this for our customers as a part of our Server Management Services.

How to Manage Docker Volumes using Docker Compose

Docker Volumes are mounted on Docker containers to store data the Docker Container generates while running. We can manage it with the help of Compose.

Manage Docker Volumes using Docker Compose

 

 

Before going into the steps to manage Docker Volumes with the help of Docker Compose we will see what are the prerequisites for this setup.

We will use the following version of Docker runtime and Docker-Compose:

1. Docker version 18.09.2, build 6247962
2. Docker-compose version 1.23.2, build 1110ad01
3. Compose file version 3: Works with 1.13.0 and above

Steps to use Docker Compose to manage Docker

Now we will see the steps our Support Engineers use to manage Docker volumes with the help of Docker Compose.

Taking Ghost CMS deployment as an example here, we will check the steps to follow.

1. First, we will create a directory ‘ComposeSamples’ and inside it, we will create a file ‘docker-compose.yaml’.
$ mkdir ComposeSamples
$ cd ComposeSamples
Contents of docker-compose.yaml:
version: "3.0"
services:
web:
image: ghost:latest
ports:
- "2368:2368"
volumes:
- cms-content:/var/lib/ghost/content

volumes:
cms-content:

The above Compose file has a website running with the latest image of ghost CMS from Docker Hub’s official repository.

A Ghost container’s default port 2368 and default mount point for the website’s contents /var/lib/ghost/content are considered as the container’s official documentation here.

Hence we can say that the volume called cms-content mounted at /var/lib/ghost/content.

[Need assistance? We are happy to help you!]

2. Syntax and Verbosity

The syntax we can introduce to a volume using docker-compose is quite simple. We will start with something similar to a container and mention the name of the volume that we want to mount inside it.

We will give the below syntax if we do not wish to give a name:

version: "3.0"
services:
web:
image: ghost:latest
ports:
- "2368:2368"
volumes:
- /var/lib/ghost/content

For making it  more verbose, we will mention the Docker Volume as a top-level definition given below:

version: "3.0"
services:
web:
image: ghost:latest
ports:
- "2368:2368"
volumes:
- cms-content:/var/lib/ghost/content
## Define that cms-content is in fact a volume.
volumes:
cms-content:

 

3. Bind Mounts

Bind mounts are parts of the host file system which can be mounted directly inside the Docker container.

For adding a bind mount we will simply mention the host directory we wish to share and the mount point inside the Docker container will get mounted.

volumes:
- /home/<USER>/projects/ghost: /var/lib/ghost/content

We can use any path instead of /home/<USER>/projects/ghost on the Docker host we want, as long as we have access to it.

When we use a more verbose syntax, the syntax file will be as given below:

volumes:
- type: bind
source: /home/USER/projects/ghost
target: /var/lib/ghost/content

Conclusion

To conclude we saw how our Support Engineers use Compose for manging Docker Volumes.

 

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Categories

Tags

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF