Docker Compose Debian

2/13/2022by admin

Docker-compose.yml calls a build command to create our MariaDB container from Debian base image. With this image, MariaDB is installed via apt and then it is setup for external access outside the container (add port mapping for external exposing or include containers on same docker network). Docker compose is an useful tool for managing multiple docker containers. It helps us to launch, update and build a group of docker containers with single commands. In case of multi container application, docker compose helped us to manage it easier. This tutorial helps you to install Docker compose on a Ubuntu 20.04 LTS Linux. Step 1 — Installing Docker Compose. Although you can install Docker Compose from the official Debian repositories, it is several minor versions behind the latest release, so in this tutorial you’ll install it from Docker’s GitHub repository. The command that follows is slightly different than the one you’ll find on the Releases page.

With a couple of tweaks the WSL (Windows Subsystem for Linux, also known as Bash for Windows) can be used with Docker for Windows.

Quick Jump: Configure Docker for Windows (Docker Desktop)Install Docker and Docker Compose within WSLConfigure WSL to Connect to Docker for WindowsEnsure Volume Mounts Work

This post only applies to WSL 1!

Check out the WSL 2 Post

Update in 2020: Now that Microsoft has released the Spring 2020 Windows update we have access to WSL 2 on all editions of Windows 10 (including Home). They even backported in support for WSL 2 in Windows versions 1903 and 1909.

I’ve recorded a video of how I have Docker Desktop along with WSL 2 working together along with other tools that I use.

I’ve decided to keep this post unmodified and fully working for WSL 1 in case you want to continue using it. Just know that I’ve moved on to using WSL 2 and that none of the steps below are necessary to do with WSL 2.

This article expects you to have WSL set up already. If you don’t, I have another article that goes over how to set up an amazing WSL based development environment within Windows. You can even run graphical apps and it doesn’t require a VM.

Onwards we go…

While the Docker daemon cannot run directly on WSL, you can use the Docker CLI to connect to a remote Docker daemon running through Docker for Windows or any other VM you create (this article covers both methods).

If you’re wondering “why not just run docker.exe and docker-compose.exe from Docker for Windows directly in WSL?”, that’s due to a bug with running Docker or Docker Compose interactively in that environment. The TL;DR is you can’t run anything in the foreground with interactive mode, which makes it unusable for real web development.

But with the Docker CLI configured to the remote Docker for Windows host it’s really awesome! Using this method, very large Rails applications respond in ~100ms (or ~5s when having to compile 10,000+ lines of Javascript and SCSS). That’s with mounted volumes too!

I use this set up pretty much every day for Rails, Flask, Phoenix, Node and Webpack driven apps. It’s very solid in terms of performance and reliability.

Configure Docker for Windows (Docker Desktop)

In the general settings, you’ll want to expose the daemon without TLS.

Docker for Windows has been recently renamed to Docker Desktop, so if your settings look slightly different than the screenshot, no worries. It’s the same thing.

It mentions “use with caution” because any time you make a network connection that’s not encrypted, it’s worth talking about but in this case it’s completely safe because we’re never connecting to it over a public network.

This is going to allow your local WSL instance to connect locally to the Docker daemon running within Docker for Windows. The traffic isn’t even leaving your dev box since the daemon is only bound to localhost, so not even other machines on your local network will be able to connect. In other words, it’s very safe for this data to be transmit over plain text.

You may also want to share any drives you plan on having your source code reside on. This step isn’t necessary but I keep my code on an internal secondary HD, so I shared my “E” drive too. If you do that, goto the “Shared Drives” setting and enable it.

Can’t use Docker for Windows?

This is only necessary if you are NOT running Docker for Windows!

You’ll want to set up your own VM to run Docker. Docker Tip #73 goes into detail on how to do this, and it even includes links to videos on how to configure the VM.

Install Docker and Docker Compose within WSL

Everyone can follow along at this point!

We still need to install Docker and Docker Compose inside of WSL because it’ll give us access to both CLI apps. We just won’t bother starting the Docker daemon.

The following instructions are for Ubuntu 18.04 / 20.04, but if you happen to use a different WSL distribution, you can follow Docker’s installation guide for your distro from Docker’s installation docs.

Install Docker

You can copy / paste all of the commands below into your WSL terminal.

Ubuntu 18.04 / 20.04 installation notes taken from Docker’s documentation:

At this point you must close your terminal and open a new one so that you can run Docker without sudo. You might as well do it now!

Install Docker Compose

We’re going to install Docker Compose using PIP instead of the pre-compiled binary on GitHub because it runs a little bit faster (both are still Python apps).

The next step is to make sure $HOME/.local/bin is set on your WSL $PATH.

You can check if it’s already set by running echo $PATH. Depending on what WSL distro you use, you may or may not see /home/nick/.local/bin (replace nick with your username).

If it’s there, you’re good to go and can skip to the next section of this post.

If it’s not there, you’ll want to add it to your $PATH. You can do that by opening up your profile file with nano ~/.profile. Then anywhere in the file, on a new line, add export PATH='$PATH:$HOME/.local/bin' and save the file.

Finally, run source ~/.profile to active your new $PATH and confirm it works by running echo $PATH. You should see it there now. Done!

Configure WSL to Connect to Docker for Windows

The next step is to configure WSL so that it knows how to connect to the remote Docker daemon running in Docker for Windows (remember, it’s listening on port 2375).

If you’re not using Docker for Windows and followed Docker Tip #73’s guide to create your own VM then you probably did this already which means you can skip the command below.

Connect to a remote Docker daemon with this 1 liner:

echo 'export DOCKER_HOST=tcp://localhost:2375' >> ~/.bashrc && source ~/.bashrc

That just adds the export line to your .bashrc file so it’s available every time you open your terminal. The source commands reloads your bash configuration so you don’t have to open a new terminal right now for it to take effect.

Verify Everything Works

Ensure Volume Mounts Work

The last thing we need to do is set things up so that volume mounts work. This tripped me up for a while because check this out…

When using WSL, Docker for Windows expects you to supply your volume paths in a format that matches this: /c/Users/nick/dev/myapp.

But, WSL doesn’t work like that. Instead, it uses the /mnt/c/Users/nick/dev/myapp format. Honestly I think Docker should change their path to use /mnt/c because it’s more clear on what’s going on, but that’s a discussion for another time.

To get things to work for now, you have 2 options. If you’re running Windows 18.03 (Spring 2018) or newer you can configure WSL to mount at / instead of /mnt and you’re all done. If you’re running 17.09 (Fall 2017) you’ll need to do something else.

Here’s step by step instructions for both versions of Windows:

Running Windows 10 18.03+ or Newer?

First up, open a WSL terminal because we need to run a few commands.

Create and modify the new WSL configuration file:

We need to set root = / because this will make your drives mounted at /c or /e instead of /mnt/c or /mnt/e.

The options = 'metadata' line is not necessary but it will fix folder and file permissions on WSL mounts so everything isn’t 777 all the time within the WSL mounts. I highly recommend you do this!

Once you make those changes, sign out and sign back in to Windows to ensure the changes take effect. Win + L isn’t enough. You’ll need to do a full blown sign out / sign in.

If you get an error the next time you start your WSL terminal don’t freak out.

It’s a bug with 18.03 and you can easily fix it. Hit CTRL + Shift + ECS to open the task manager, goto the “Services” tab, find the “LxssManager” service and restart it.

This seems to only happen if you sign out of Windows instead of doing a full reboot and will likely be fixed in a future 18.03+ patch.

Once that’s done, you’re all set. You’ll be able to access your mounts and they will work perfectly with Docker and Docker Compose without any additional adjustments. For example you’ll be able to use .:/myapp in a docker-compose.yml file, etc..

What terminal emulator are you using?

If you’re using ConEmu, then you’ll want to make sure to upgrade to the latest alpha release (at least 18.05.06+ which you can see in the title bar of the settings). It contains a patched wslbridge.exe file to support a custom WSL root mount point.

Docker Compose Debian

The default Ubuntu WSL terminal supports this by default, so you’re all good. I don’t know if other terminals support this yet. Let me know in the comments.

You're all done! You can skip the 17.09 steps below if you followed the above steps.

Running Windows 10 17.09?

First up, open a WSL terminal because we need to run a few commands.

Bind custom mount points to fix Docker for Windows and WSL differences:

You’ll want to repeat those commands for any drives that you shared, such as d or e, etc..

Verify that it works by running: ls -la /c. You should see the same exact output as running ls -la /mnt/c because /mnt/c is mounted to /c.

At this point you’re golden. You can use volume mount paths like .:/myapp in your Docker Compose files and everything will work like normal. That’s awesome because that format is what native Linux and MacOS users also use.

It’s worth noting that whenever you run a docker-compose up, you’ll want to make sure you navigate to the /c/Users/nick/dev/myapp location first, otherwise your volume won’t work. In other words, never access /mnt/c directly.

Technically you could use a symlink instead of a bind mount, but I’ve been burned in the past when it came to using symlinks and having certain tools not work because they failed to follow them correctly. Better safe than sorry here.

However, feel free to use symlinks inside WSL to access your bind mount. For example my Dev folder lives all the way in /e/Backup/VMs/workstation/home/nick/Dev and there’s no way in heck I’m going to always type that when I want to access my development files.

So inside WSL I created a symlink with ln -s /e/Backup/VMs/workstation/home/nick/Dev ~/Dev and now I can just type cd ~/Dev to access my files and everything works.

Automatically set up the bind mount:

Unfortunately you will have to run that sudo mount command every time you open a new terminal because WSL doesn’t support mounting through /etc/fstab yet (edit: it does in 18.09+, but if you’re using 18.09+ you should follow the 18.03+ steps).

But we can work around that limitation by just mounting it in your ~/.bashrc file. This is a little dirty but as far as I know, I think this is the only way to do it, so if you know of a better way, please let me know.

You can do that with this 1 liner: echo 'sudo mount --bind /mnt/c /c' >> ~/.bashrc && source ~/.bashrc and make sure to repeat the command for any additional drives you shared with Docker for Windows. By the way, you don’t need to mkdir because we already did it.

Yes I know, that means you will be prompt for your root password every time you open a terminal, but we can get around that too because Linux is cool like that.

Allow your user to bind a mount without a root password:

To do that, run the sudo visudo command.

That should open up nano (a text editor). Goto the bottom of the file and add this line: nick ALL=(root) NOPASSWD: /bin/mount, but replace “nick” with your username.

Docker compose debian container

That just allows your user to execute the sudo mount command without having to supply a password. You can save the file with CTRL + O, confirm and exit with CTRL + X.

Mission complete. You’re all set to win at life by using Docker for Windows and WSL.

Let me know how it goes in the comments!

Estimated reading time: 12 minutes

To get started with Docker CE on Debian, make sure youmeet the prerequisites, theninstall Docker.


Docker EE customers

Docker EE is not supported on Debian. For a list of supported operating systemsand distributions for different Docker editions, seeDocker variants.

OS requirements

To install Docker CE, you need the 64-bit version of one of these Debian orRaspbian versions:

  • Buster 10 (Docker CE 17.11 Edge only)
  • Stretch 9 (stable) / Raspbian Stretch
  • Jessie 8 (LTS) / Raspbian Jessie
  • Wheezy 7.7 (LTS)

Docker CE is supported on both x86_64 (or amd64) and armhf architectures for Jessie andStretch.

Uninstall old versions

Older versions of Docker were called docker or docker-engine. If these areinstalled, uninstall them:

It’s OK if apt-get reports that none of these packages are installed.

The contents of /var/lib/docker/, including images, containers, volumes, andnetworks, are preserved. The Docker CE package is now called docker-ce.

Extra steps for Wheezy 7.7

  • You need at least version 3.10 of the Linux kernel. Debian Wheezy ships withversion 3.2, so you may need toupdate the kernel.To check your kernel version:

  • Enable the backports repository. See theDebian documentation.

Install Docker CE

You can install Docker CE in different ways, depending on your needs:

  • Most usersset up Docker’s repositories and installfrom them, for ease of installation and upgrade tasks. This is therecommended approach, except for Raspbian.

  • Some users download the DEB package andinstall it manually and manageupgrades completely manually. This is useful in situations such as installingDocker on air-gapped systems with no access to the internet.

  • In testing and development environments, some users choose to use automatedconvenience scripts to install Docker.This is currently the only approach for Raspbian.

Install using the repository

Before you install Docker CE for the first time on a new host machine, you needto set up the Docker repository. Afterward, you can install and update Dockerfrom the repository.

Raspbian users cannot use this method!

For Raspbian, installing using the repository is not yet supported. You mustinstead use the convenience script.

Set up the repository

  1. Update the apt package index:

  2. Install packages to allow apt to use a repository over HTTPS:

  3. Add Docker’s official GPG key:

    Verify that you now have the key with the fingerprint9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for thelast 8 characters of the fingerprint.

  4. Use the following command to set up the stable repository. You alwaysneed the stable repository, even if you want to install builds from theedge or test repositories as well. To add the edge ortest repository, add the word edge or test (or both) after theword stable in the commands below.

    Note: The lsb_release -cs sub-command below returns the name of yourDebian distribution, such as jessie.

    To also add the edge repository, add edge after stable on the lastline of the command.

  5. Wheezy only: The version of add-apt-repository on Wheezy adds a deb-srcrepository that does not exist. You need to comment out this repository orrunning apt-get update fails. Edit /etc/apt/sources.list. Find theline like the following, and comment it out or remove it:

    Save and exit the file.

    Note: Starting with Docker 17.06, stable releases are also pushed tothe edge and test repositories.

    Learn about stable and edge channels.

Install Docker CE

Note: This procedure works for Debian on x86_64 / amd64, Debian ARM,or Raspbian.

  1. Update the apt package index.

  2. Install the latest version of Docker CE, or go to the next step to install a specific version:

    Got multiple Docker repositories?

    If you have multiple Docker repositories enabled, installingor updating without specifying a version in the apt-get install orapt-get update command always installs the highest possible version,which may not be appropriate for your stability needs.

  3. To install a specific version of Docker CE, list the available versions in the repo, then select and install:

    a. List the versions available in your repo:

    b. Install a specific version by its fully qualified package name, which is the package name (docker-ce) plus the version string (2nd column) up to the first hyphen, separated by a an equals sign (=), for example, docker-ce=18.03.0.ce.

    The Docker daemon starts automatically.

  4. Verify that Docker CE is installed correctly by running the hello-worldimage.



    This command downloads a test image and runs it in a container. When thecontainer runs, it prints an informational message and exits.

Docker CE is installed and running. The docker group is created but no usersare added to it. You need to use sudo to run Dockercommands. Continue to Linux postinstall to allownon-privileged users to run Docker commands and for other optional configurationsteps. For Raspbian, you can optionallyinstall Docker Compose for Raspbian.

Upgrade Docker CE

To upgrade Docker CE, first run sudo apt-get update, then follow theinstallation instructions, choosing the new version you wantto install.

Install from a package

If you cannot use Docker’s repository to install Docker CE, you can download the.deb file for your release and install it manually. You need to downloada new file each time you want to upgrade Docker.

  1. Go to,choose your Debian version, browse to pool/stable/, choose eitheramd64 or armhf, and download the .deb file for the Docker CE version youwant to install.

    Note: To install an edge package, change the wordstable in the URL to edge.Learn about stable and edge channels.

  2. Install Docker CE, changing the path below to the path where you downloadedthe Docker package.

    The Docker daemon starts automatically.

  3. Verify that Docker CE is installed correctly by running the hello-worldimage.

    This command downloads a test image and runs it in a container. When thecontainer runs, it prints an informational message and exits.

Docker CE is installed and running. The docker group is created but no usersare added to it. You need to use sudo to run Dockercommands. Continue to Post-installation steps for Linuxto allow non-privileged users to run Docker commands and for other optionalconfiguration steps. For Raspbian, you can optionallyinstall Docker Compose for Raspbian.

Upgrade Docker CE

To upgrade Docker, download the newer package file and repeat theinstallation procedure, pointing to the new file.

Install using the convenience script

Docker provides convenience scripts at get.docker.comand for installing edge andtesting versions of Docker CE into development environments quickly andnon-interactively. The source code for the scripts is in thedocker-install repository.Using these scripts is not recommended for productionenvironments, and you should understand the potential risks before you usethem:

  • The scripts require root or sudo privileges to run. Therefore,you should carefully examine and audit the scripts before running them.
  • The scripts attempt to detect your Linux distribution and version andconfigure your package management system for you. In addition, the scripts donot allow you to customize any installation parameters. This may lead to anunsupported configuration, either from Docker’s point of view or from your ownorganization’s guidelines and standards.
  • The scripts install all dependencies and recommendations of the packagemanager without asking for confirmation. This may install a large number ofpackages, depending on the current configuration of your host machine.
  • The script does not provide options to specify which version of Docker to install,and installs the latest version that is released in the “edge” channel.
  • Do not use the convenience script if Docker has already been installed on thehost machine using another mechanism.

This example uses the script at toinstall the latest release of Docker CE on Linux. To install the latesttesting version, use instead. Ineach of the commands below, replace each occurrence of get with test.


Always examine scripts downloaded from the internet beforerunning them locally.

Docker CE is installed. It starts automatically on DEB-based distributions. OnRPM-based distributions, you need to start it manually using the appropriatesystemctl or service command. As the message indicates, non-root users can’trun Docker commands by default.

Upgrade Docker after using the convenience script

ComposeDocker-compose linux install

Command Line Reference

If you installed Docker using the convenience script, you should upgrade Dockerusing your package manager directly. There is no advantage to re-running theconvenience script, and it can cause issues if it attempts to re-addrepositories which have already been added to the host machine.

Install Docker Compose for Raspbian

You can install Docker Compose using pip:

Hypriot provides a staticbinary of docker-compose for Raspbian. It may not always be up to date, but ifspace is at a premium, you may find it useful. To use it, first follow Hypriot’sinstructions for setting up the repository,then run the following command:

Uninstall Docker CE

  1. Uninstall the Docker CE package:

  2. Images, containers, volumes, or customized configuration files on your hostare not automatically removed. To delete all images, containers, andvolumes:

You must delete any edited configuration files manually.

Next steps

  • Continue to Post-installation steps for Linux

  • Continue with the User Guide.

User Guide

requirements, apt, installation, debian, install, uninstall, upgrade, update
Comments are closed.