Install Docker Compose 3.7 Ubuntu



I used to think that Docker Compose was used solely to spin up multiple containers, in fact I blogged about doing just that here.

Docker installed on your server, following Steps 1 and 2 of How To Install and Use Docker on Ubuntu 20.04. Docker Compose installed on your server, following Step 1 of How To Install and Use Docker Compose on Ubuntu 20.04. Step 1 — Obtaining the Demo Application. To get started, we’ll fetch the demo Laravel application from its Github. Docker-compose version docker-compose version 1.27.4, build 40524192 docker-py version: 4.3.1 CPython version: 3.7.7 OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019 👍 1 🎉 1 Copy link. Docker Compose is a great tool for development, testing, and staging environments, as well as CI workflows. Install Docker Compose on RHEL 8 / CentOS 8. Follow our separate guide on installation of latest Docker Compose on Linux. Install Docker Compose on Linux. For the sake of keeping this guide brief, we won’t dive into Docker compose usage. Browse other questions tagged docker docker-compose composer-php or ask your own question. The Overflow Blog Podcast 322: Getting Dev and Ops to actually work together. Install OpenProject with Docker. Docker is a way to distribute self-contained applications easily. We provide a Docker image for the Community Edition that you can very easily install and upgrade on your servers.

That opinion changed when I went to DockerCon in 2018 and had a chance to speak to some Docker Captains who told me that they used compose for everything!

And it makes sense, let’s have a look at spinning up one container running SQL Server 2019: –

Install docker compose 3.7 ubuntu download

Quite a bit to type there, no? Do we really want to be typing that out every time we run a container?

And it gets even worse if we want to persist our databases from one container to another: –

That’s a lot of typing! And if we try to create a database with the default values set in that statement, we’ll get the following error: –

Install

CREATE FILE encountered operating system error 2(The system cannot find the file specified.) while attempting to open or create the physical file ‘/var/opt/sqlserver/testdatabase.mdf’.

This is because SQL in 2019 runs as non-root. This is a good thing but it means that after the container comes up, we have to run: –

The solution here is to create a custom image with the volume created and permissions set.

But wouldn’t it be easier to just have to run one command to spin up a custom 2019 image, with volumes created and permissions set?

Enter Docker Compose.

I’ve created a GitHub repository here with all the necessary files: –
https://github.com/dbafromthecold/SqlServerDockerCompose

If we clone that repo down, we’ll get the following: –

Docker

Install Docker Compose 3.7 Ubuntu Free

Let’s go through each of the files

.gitignore
Standard ignore file, this is to prevent the sapassword.env file from being uploaded to Github

docker-compose.yaml
Compose file that when executed will reference our dockerfile and build us a custom image

dockerfile
File to create a custom SQL 2019 image

sapassword.env
Environment variable file to contain our SA password. We’ll need to create this file, it’s not in the repo

sqlserver.env
Environment variable file that contains all the environment variables required to spin up SQL Server in a container

Let’s dive in a little deeper and first have a look at the dockerfile: –

This file when executed is going to create a custom SQL 2019 image, not from the microsoft images but installed via apt-get (the way you would install SQL on Linux).

It’s based on the Ubuntu 18.04 image and the steps are: –

  1. Pull down the Ubuntu 18.04 image and base this new image off it
  2. Create the mssql user
  3. Install SQL Server as you would on Linux, detailed instructions here
  4. Create the required directories
  5. Change the owner of those directories to the mssql user
  6. Switch over to run the next command as the mssql user
  7. Start SQL Server

Ok, cool. Let’s now have a look at the docker-compose.yaml file: –

Stepping through this we: –

  1. Define a service called sqlserver1, setting a build context to the current directory and specifying our dockerfile
  2. Set our ports, mapping 15789 on the host to 1433 in the container
  3. Specify our environment variable files
  4. Then set our volumes, matching the directories created in the dockerfile

And finally, let’s have a look at the two environment variable files: –

sqlserver.env

sapassword.env

The SA password is set in a separate file so that we don’t end up putting it somewhere public 🙂
The other file can contain any environment variable for SQL Server, a full list is here.

Install docker compose 3.7 ubuntu windows 10Install Docker Compose 3.7 Ubuntu

Awesome stuff. OK, now we can run: –

Install Docker Compose 3.7 Ubuntu Windows 7

And we can check the objects created by compose by running: –

There we can see our custom network, volumes, image, and container up and running!

So we’re good to do our work on SQL Server 2019 and when we’re finished we can just run: –

Install Docker Compose 3.7 Ubuntu Windows 10

That’ll delete our custom network and the container but we’ll still have our custom image and volumes, ready for next time we want to do some work against SQL Server 2019.

Install Docker Compose 3.7 Ubuntu Download

Thanks for reading!