Estimated reading time: 7 minutes
You can run Compose on macOS, Windows, and 64-bit Linux.
Prerequisites
For example, to start a new Docker container for the MySQL Community Server, use this command: docker run -name=mysql1 -restart on-failure -d mysql/mysql-server:8.0. To start a new Docker container for the MySQL Enterprise Server with a Docker image downloaded from the OCR, use this command. Jul 25, 2016 For comparison, MySQL with MySQL Workbench CE on Windows is phenomenal. Docker on Win 10 is an afterthought and treated by the Docker team like an orphan.
Docker Compose relies on Docker Engine for any meaningful work, so make sure youhave Docker Engine installed either locally or remote, depending on your setup.
On desktop systems like Docker Desktop for Mac and Windows, Docker Compose isincluded as part of those desktop installs.
On Linux systems, first install theDocker Enginefor your OS as described on the Get Docker page, then come back here forinstructions on installing Compose onLinux systems.
To run Compose as a non-root user, see Manage Docker as a non-root user.
Install Compose
Follow the instructions below to install Compose on Mac, Windows, Windows Server2016, or Linux systems, or find out about alternatives like using the pip
Python package manager or installing Compose as a container.
Install a different version
The instructions below outline installation of the current stable release(v1.28.6) of Compose. To install a different version ofCompose, replace the given release number with the one that you want. Composereleases are also listed and available for direct download on theCompose repository release page on GitHub.To install a pre-release of Compose, refer to the install pre-release buildssection.
Install Compose on macOS
Docker Desktop for Mac includes Compose alongwith other Docker apps, so Mac users do not need to install Compose separately.For installation instructions, see Install Docker Desktop on Mac.
Install Compose on Windows desktop systems
Docker Desktop for Windows includes Composealong with other Docker apps, so most Windows users do not need toinstall Compose separately. For install instructions, see Install Docker Desktop on Windows.
If you are running the Docker daemon and client directly on MicrosoftWindows Server, follow the instructions in the Windows Server tab.
Install Compose on Windows Server
Follow these instructions if you are running the Docker daemon and client directlyon Microsoft Windows Server and want to install Docker Compose.
Start an “elevated” PowerShell (run it as administrator).Search for PowerShell, right-click, and chooseRun as administrator. When asked if you want to allow this appto make changes to your device, click Yes.
In PowerShell, since GitHub now requires TLS1.2, run the following:
Then run the following command to download the current stable release ofCompose (v1.28.6):
Note: On Windows Server 2019, you can add the Compose executable to $Env:ProgramFilesDocker
. Because this directory is registered in the system PATH
, you can run the docker-compose --version
command on the subsequent step with no additional configuration.
Test the installation.
Install Compose on Linux systems
On Linux, you can download the Docker Compose binary from theCompose repository release page on GitHub.Follow the instructions from the link, which involve running the curl
commandin your terminal to download the binaries. These step-by-step instructions arealso included below.
For alpine
, the following dependency packages are needed:py-pip
, python3-dev
, libffi-dev
, openssl-dev
, gcc
, libc-dev
, rust
, cargo
and make
.
Run this command to download the current stable release of Docker Compose:
To install a different version of Compose, substitute
1.28.6
with the version of Compose you want to use.If you have problems installing with
curl
, seeAlternative Install Options tab above.Apply executable permissions to the binary:
Note: If the command docker-compose
fails after installation, check your path.You can also create a symbolic link to /usr/bin
or any other directory in your path.
For example:
Optionally, install command completion for the
bash
andzsh
shell.Test the installation.
Alternative install options
Install using pip
For alpine
, the following dependency packages are needed:py-pip
, python3-dev
, libffi-dev
, openssl-dev
, gcc
, libc-dev
, rust
, cargo
, and make
.
Compose can be installed frompypi using pip
. If you installusing pip
, we recommend that you use avirtualenv because many operatingsystems have python system packages that conflict with docker-composedependencies. See the virtualenvtutorial to getstarted.
If you are not using virtualenv,
pip version 6.0 or greater is required.
Install as a container
Compose can also be run inside a container, from a small bash script wrapper. Toinstall compose as a container run this command:
Install pre-release builds
If you’re interested in trying out a pre-release build, you can download releasecandidates from the Compose repository release page on GitHub.Follow the instructions from the link, which involves running the curl
commandin your terminal to download the binaries.
Pre-releases built from the “master” branch are also available for download athttps://dl.bintray.com/docker-compose/master/.
Pre-release builds allow you to try out new features before they are released,but may be less stable.
Upgrading
If you’re upgrading from Compose 1.2 or earlier, remove ormigrate your existing containers after upgrading Compose. This is because, as ofversion 1.3, Compose uses Docker labels to keep track of containers, and yourcontainers need to be recreated to add the labels.
If Compose detects containers that were created without labels, it refusesto run, so that you don’t end up with two sets of them. If you want to keep usingyour existing containers (for example, because they have data volumes you wantto preserve), you can use Compose 1.5.x to migrate them with the followingcommand:
Alternatively, if you’re not worried about keeping them, you can remove them.Compose just creates new ones.
Uninstallation
To uninstall Docker Compose if you installed using curl
:
To uninstall Docker Compose if you installed using pip
:
Got a “Permission denied” error?
If you get a “Permission denied” error using either of the abovemethods, you probably do not have the proper permissions to removedocker-compose
. To force the removal, prepend sudo
to either of the abovecommands and run again.
Where to go next
compose, orchestration, install, installation, docker, documentation7.6.1 Basic Steps for MySQL Server Deployment with Docker
The MySQL Docker images maintained by the MySQL team are built specifically for Linux platforms. Other platforms are not supported, and users using these MySQL Docker images on them are doing so at their own risk. See the discussion here for some known limitations for running these containers on non-Linux operating systems.
Downloading a MySQL Server Docker Image
For users of MySQL Enterprise Edition: A subscription is required to use the Docker images for MySQL Enterprise Edition. Subscriptions work by a Bring Your Own License model; see How to Buy MySQL Products and Services for details.
Downloading the server image in a separate step is not strictly necessary; however, performing this step before you create your Docker container ensures your local image is up to date. To download the MySQL Community Edition image, run this command:
The tag
is the label for the image version you want to pull (for example, 5.6
, 5.7
, 8.0
, or latest
). If :
is omitted, the tag
latest
label is used, and the image for the latest GA version of MySQL Community Server is downloaded. Refer to the list of tags for available versions on the mysql/mysql-server page in the Docker Hub.
To download the MySQL Community Edition image from the Oracle Container Registry (OCR), run this command:
To download the MySQL Enterprise Edition image from the OCR, you need to first accept the license agreement on the OCR and log in to the container repository with your Docker client:
Visit the OCR at https://container-registry.oracle.com/ and choose MySQL.
Under the list of MySQL repositories, choose
enterprise-server
.If you have not signed in to the OCR yet, click the button on the right of the page, and then enter your Oracle account credentials when prompted to.
Follow the instructions on the right of the page to accept the license agreement.
Log in to the OCR with your Docker client (the
docker
command) using thedocker login
command:
Docker Php Mysql Windows
Download the Docker image for MySQL Enterprise Edition from the OCR with this command:
There are different choices for
, corresponding to different versions of MySQL Docker images provided by the OCR:tag
8.0
,8.0.
(x
x
is the latest version number in the 8.0 series),latest
: MySQL 8.0, the latest GA5.7
,5.7.
(y
y
is the latest version number in the 5.7 series): MySQL 5.7
To download the MySQL Enterprise Edition image from My Oracle Support website, go onto the website, sign in to your Oracle account, and perform these steps once you are on the landing page:
Select the Patches and Updates tab.
Go to the Patch Search region and, on the Search tab, switch to the Product or Family (Advanced) subtab.
Enter “MySQL Server” for the Product field, and the desired version number in the Release field.
Use the dropdowns for additional filters to select Description—contains, and enter “Docker” in the text field.
The following figure shows the search settings for the MySQL Enterprise Edition image for MySQL Server 8.0:
Click the button and, from the result list, select the version you want, and click the button.
In the File Download dialogue box that appears, click and download the
.zip
file for the Docker image.
Unzip the downloaded .zip
archive to obtain the tarball inside (mysql-enterprise-server-
), and then load the image by running this command: version
.tar
You can list downloaded Docker images with this command:
Starting a MySQL Server Instance
To start a new Docker container for a MySQL Server, use the following command:
The image name can be obtained using the docker images command, as explained in Downloading a MySQL Server Docker Image.
The --name
option, for supplying a custom name for your server container, is optional; if no container name is supplied, a random one is generated.
The --restart
option is for configuring the restart policy for your container; it should be set to the value on-failure
, to enable support for server restart within a client session (which happens, for example, when the RESTART statement is executed by a client or during the configuration of an InnoDB cluster instance). With the support for restart enabled, issuing a restart within a client session causes the server and the container to stop and then restart. Support for server restart is available for MySQL 8.0.21 and later.
For example, to start a new Docker container for the MySQL Community Server, use this command:
To start a new Docker container for the MySQL Enterprise Server with a Docker image downloaded from the OCR, use this command:
To start a new Docker container for the MySQL Enterprise Server with a Docker image downloaded from My Oracle Support, use this command:
If the Docker image of the specified name and tag has not been downloaded by an earlier docker pull or docker run command, the image is now downloaded. Initialization for the container begins, and the container appears in the list of running containers when you run the docker ps command. For example:
The container initialization might take some time. When the server is ready for use, the STATUS
of the container in the output of the docker ps command changes from (health: starting)
to (healthy)
.
The -d
option used in the docker run command above makes the container run in the background. Use this command to monitor the output from the container:
Once initialization is finished, the command's output is going to contain the random password generated for the root user; check the password with, for example, this command:
Connecting to MySQL Server from within the Container
Once the server is ready, you can run the mysql client within the MySQL Server container you just started, and connect it to the MySQL Server. Use the docker exec -it command to start a mysql client inside the Docker container you have started, like the following:
When asked, enter the generated root password (see the last step in Starting a MySQL Server Instance above on how to find the password). Because the MYSQL_ONETIME_PASSWORD
option is true by default, after you have connected a mysql client to the server, you must reset the server root password by issuing this statement:
Substitute password
with the password of your choice. Once the password is reset, the server is ready for use.
Container Shell Access
To have shell access to your MySQL Server container, use the docker exec -it command to start a bash shell inside the container:
You can then run Linux commands inside the container. For example, to view contents in the server's data directory inside the container, use this command:
Stopping and Deleting a MySQL Container
To stop the MySQL Server container we have created, use this command:
docker stop sends a SIGTERM signal to the mysqld process, so that the server is shut down gracefully.
Also notice that when the main process of a container (mysqld in the case of a MySQL Server container) is stopped, the Docker container stops automatically.
To start the MySQL Server container again:
Docker Mysql Windows Image
To stop and start again the MySQL Server container with a single command:
To delete the MySQL container, stop it first, and then use the docker rm command:
If you want the Docker volume for the server's data directory to be deleted at the same time, add the -v
option to the docker rm command.
Docker Hub
Upgrading a MySQL Server Container
Mysql Docker On Windows
Before performing any upgrade to MySQL, follow carefully the instructions in Chapter 10, Upgrading MySQL. Among other instructions discussed there, it is especially important to back up your database before the upgrade.
The instructions in this section require that the server's data and configuration have been persisted on the host. See Persisting Data and Configuration Changes for details.
Follow these steps to upgrade a Docker installation of MySQL 5.7 to 8.0:
Stop the MySQL 5.7 server (container name is
mysql57
in this example):Download the MySQL 8.0 Server Docker image. See instructions in Downloading a MySQL Server Docker Image; make sure you use the right tag for MySQL 8.0.
Start a new MySQL 8.0 Docker container (named
mysql80
in this example) with the old server data and configuration (with proper modifications if needed—see Chapter 10, Upgrading MySQL) that have been persisted on the host (by bind-mounting in this example). For the MySQL Community Server, run this command:If needed, adjust
mysql/mysql-server
to the correct image name—for example, replace it withcontainer-registry.oracle.com/mysql/enterprise-server
for MySQL Enterprise Edition images downloaded from the OCR, ormysql/enterprise-server
for MySQL Enterprise Edition images downloaded from My Oracle Support.Wait for the server to finish startup. You can check the status of the server using the docker ps command (see Starting a MySQL Server Instance for how to do that).
For MySQL 8.0.15 and earlier: Run the mysql_upgrade utility in the MySQL 8.0 Server container (not required for MySQL 8.0.16 and later):
When prompted, enter the root password for your old MySQL 5.7 Server.
Finish the upgrade by restarting the MySQL 8.0 Server container:
Docker Compose Mysql Windows
More Topics on Deploying MySQL Server with Docker
For more topics on deploying MySQL Server with Docker like server configuration, persisting data and configuration, server error log, and container environment variables, see Section 7.6.2, “More Topics on Deploying MySQL Server with Docker”.