Docker Compose Mac



  1. Docker Compose Tutorial
  2. Docker-compose On Mac
  3. Docker Compose Mac Localhost
  4. Install Docker-compose Mac
  5. Docker Compose Mac Address

Estimated reading time: 3 minutes

Docker Desktop for Mac is the Community version of Docker for Mac.You can download Docker Desktop for Mac from Docker Hub.

By downloading Docker Desktop, you agree to the terms of the Docker Software End User License Agreement and the Docker Data Processing Agreement.

The Docker Desktop installation includes Docker Engine, Docker CLI client, Docker Compose, Notary, Kubernetes, and Credential Helper. Install and run Docker Desktop on Mac Double-click Docker.dmg to open the installer, then drag the Docker icon to the Applications folder. Get a head start on your coding by leveraging Docker images to efficiently develop your own unique applications on Windows and Mac. Create your multi container application using the Docker Compose CLI.

System requirements

Your Mac must meet the following requirements to successfully install Docker Desktop:

  • macOS must be version 10.14 or newer. That is, Mojave, Catalina, or Big Sur. We recommend upgrading to the latest version of macOS.

    If you experience any issues after upgrading your macOS to version 10.15, you must install the latest version of Docker Desktop to be compatible with this version of macOS.

    Note

    Docker supports Docker Desktop on the most recent versions of macOS. That is, the current release of macOS and the previous two releases. As new major versions of macOS are made generally available, Docker stops supporting the oldest version and supports the newest version of macOS (in addition to the previous two releases). Docker Desktop currently supports macOS Mojave, macOS Catalina, and macOS Big Sur.

  • At least 4 GB of RAM.

  • VirtualBox prior to version 4.3.30 must not be installed as it is not compatible with Docker Desktop.

  • After furious account creating, downloading, installing and proxy-configuring the latest version of Docker was once again setup on my mac. Docker-compose up worked without any issues. I thing the problem was (or is) that my installment of Docker dated back to times when it was called Docker Toolbox (and did not include the docker-credential.
  • Install Docker Compose. If you installed Docker Desktop for either Windows or Mac, you already have Docker Compose! Play-with-Docker instances already have Docker Compose installed as well. If you are on a Linux machine, you will need to install Docker Compose using the instructions here.

What’s included in the installer

The Docker Desktop installation includes Docker Engine, Docker CLI client, Docker Compose, Notary, Kubernetes, and Credential Helper.

Install and run Docker Desktop on Mac

  1. Double-click Docker.dmg to open the installer, then drag the Docker icon to the Applications folder.

  2. Double-click Docker.app in the Applications folder to start Docker. (In the example below, the Applications folder is in “grid” view mode.)

    The Docker menu in the top status bar indicates that Docker Desktop is running, and accessible from a terminal.

    If you’ve just installed the app, Docker Desktop launches the onboarding tutorial. The tutorial includes a simple exercise to build an example Docker image, run it as a container, push and save the image to Docker Hub.

  3. Click the Docker menu () to seePreferences and other options.

  4. Select About Docker to verify that you have the latest version.

Congratulations! You are now successfully running Docker Desktop.

If you would like to rerun the tutorial, go to the Docker Desktop menu and select Learn.

Automatic updates

Starting with Docker Desktop 3.0.0, updates to Docker Desktop will be available automatically as delta updates from the previous version.

When an update is available, Docker Desktop automatically downloads it to your machine and displays an icon to indicate the availability of a newer version. All you need to do now is to click Update and restart from the Docker menu. This installs the latest update and restarts Docker Desktop for the changes to take effect.

Uninstall Docker Desktop

To uninstall Docker Desktop from your Mac:

  1. From the Docker menu, select Troubleshoot and then select Uninstall.
  2. Click Uninstall to confirm your selection.
Docker compose mac host network

Important

Docker Compose Tutorial

Uninstalling Docker Desktop destroys Docker containers, images, volumes, andother Docker related data local to the machine, and removes the files generatedby the application. Refer to the back up and restore datasection to learn how to preserve important data before uninstalling.

Where to go next

  • Getting started provides an overview of Docker Desktop on Mac, basic Docker command examples, how to get help or give feedback, and links to other topics about Docker Desktop on Mac.
  • Troubleshooting describes common problems, workarounds, howto run and submit diagnostics, and submit issues.
  • FAQs provide answers to frequently asked questions.
  • Release notes lists component updates, new features, and improvements associated with Docker Desktop releases.
  • Get started with Docker provides a general Docker tutorial.
  • Back up and restore data provides instructionson backing up and restoring data related to Docker.
mac, install, download, run, docker, local-->

Docker Compose is a tool that was developed to help define and share multi-container applications. With Compose, you can create a YAML file to define the services and with a single command, can spin everything up or tear it all down.

The big advantage of using Compose is you can define your application stack in a file, keep it at the root of your project repo (it's now version controlled), and easily enable someone else to contribute to your project. Someone would only need to clone your repo and start the compose app. In fact, you might see quite a few projects on GitHub/GitLab doing exactly this now.

So, how do you get started?

Install Docker Compose

If you installed Docker Desktop for either Windows or Mac, you already have Docker Compose! Play-with-Docker instances already have Docker Compose installed as well. If you are on a Linux machine, you will need to install Docker Compose using the instructions here.

Docker-compose On Mac

After installation, you should be able to run the following and see version information.

Docker

Create the compose file

Compose
  1. At the root of the app project, create a file named docker-compose.yml.

  2. In the compose file, we'll start off by defining the schema version. In most cases, it's best to use the latest supported version. You can look at the Compose file reference for the current schema versions and the compatibility matrix.

  3. Next, define the list of services (or containers) you want to run as part of your application.

And now, you'll start migrating a service at a time into the compose file.

Define the App Service

To remember, this was the command you used to define your app container (replace the characters with ` in Windows PowerShell).

  1. First, define the service entry and the image for the container. You can pick any name for the service. The name will automatically become a network alias, which will be useful when defining the MySQL service.

  2. Typically, you'll see the command close to the image definition, although there is no requirement on ordering. So, go ahead and move that into the file.

  3. Migrate the -p 3000:3000 part of the command by defining the ports for the service. You'll use the short syntax here, but there is also a more verbose long syntax available as well.

  4. Next, migrate both the working directory (-w /app) and the volume mapping (-v ${PWD}:/app) by using the working_dir and volumes definitions. Volumes also has a short and long syntax.

    One advantage of Docker Compose volume definitions is you can use relative paths from the current directory.

  5. Finally, migrate the environment variable definitions using the environment key.

Define the MySQL service

Now, it's time to define the MySQL service. The command that you used for that container was the following (replace the characters with ` in Windows PowerShell):

  1. First, define the new service and name it mysql so it automatically gets the network alias. Specify the image to use as well.

  2. Next, define the volume mapping. When you ran the container with docker run, the named volume was created automatically. However, that doesn't happen when running with Compose. You need to define the volume in the top-level volumes: section and then specify the mountpoint in the service config. By simply providing only the volume name, the default options are used. There are many more options available though.

  3. Finally, you only need to specify the environment variables.

At this point, the complete docker-compose.yml should look like this:

Run the application stack

Now that you have the docker-compose.yml file, you can start it up!

  1. First, make sure no other copies of the app and database are running (docker ps and docker rm -f <ids>).

  2. Start up the application stack using the docker-compose up command. Add the -d flag to run everything in the background. Alternatively, you can right-click on your Compose file and select the Compose Up option for the VS Code side bar.

    When you run this, you should see output like this:

    You'll notice that the volume was created as well as a network! By default, Docker Compose automatically creates a network specifically for the application stack (which is why you didn't define one in the compose file).

  3. Look at the logs using the docker-compose logs -f command. You'll see the logs from each of the services interleaved into a single stream. This is incredibly useful when you want to watch for timing-related issues. The -f flag 'follows' the log, so will give you live output as it's generated.

    If you don't already, you'll see output that looks like this:

    The service name is displayed at the beginning of the line (often colored) to help distinguish messages. If you want to view the logs for a specific service, you can add the service name to the end of the logs command (for example, docker-compose logs -f app).

    Tip

    Waiting for the DB before starting the appWhen the app is starting up, it actually sits and waits for MySQL to be up and ready before trying to connect to it.Docker doesn't have any built-in support to wait for another container to be fully up, running, and ready before starting another container. For Node-based projects, you can use the wait-port dependency. Similar projects exist for other languages/frameworks.

  4. At this point, you should be able to open your app and see it running. And hey! You're down to a single command!

See the app stack in the Docker extension

If you look at the Docker extension, you can change the grouping options using the 'cog' and 'group by'. In this instance, you want to see containers grouped by Compose Project name:

If you twirl down the network, you will see the two containers you defined in the compose file.

Tear it all down

When you're ready to tear it all down, simply run docker-compose down, or right-click on the application in the containers list in the VS Code Docker extension and select Compose Down. The containers will stop and the network will be removed.

Warning

Removing VolumesBy default, named volumes in your compose file are NOT removed when running docker-compose down. If you want to remove the volumes, you will need to add the --volumes flag.

Once torn down, you can switch to another project, run docker-compose up and be ready to contribute to that project! It really doesn't get much simpler than that!

Recap

Docker Compose Mac Localhost

In this section, you learned about Docker Compose and how it helps dramatically simplify the defining and sharing of multi-service applications. You created a Compose file by translating the commands you were using into the appropriate compose format.

At this point, you're starting to wrap up the tutorial. However, there are a few best practices about image building to cover, as there is a big issue with the Dockerfile you've been using. So, let's take a look!

Install Docker-compose Mac

Next steps

Docker Compose Mac Address

Continue with the tutorial!