Get an overview of the basic syntax for a Docker Cloud stack file.
- [Instructor] Once you've opened the door on using infrastructure as code, you'll never want to close it. The advantages are vast. But personally I've always felt the biggest advantage is the ability to recreate an environment exactly for development or testing purposes. Creating a stack file in Docker Cloud will allow you to define the complete architecture. You'll be able to duplicate this architecture inside Docker Cloud for as many situations as you need. This definition you'll be creating offers a level of abstraction that makes it possible to scale copies of your architecture to fit your exact needs.
A stack file in Docker is a collection of services, that's it. A stack file is a YAML file defining a collection of services. If you're unfamiliar with YAML, it's a standard data format like JSON or XML, but designed to be more human readable. Here we are back at the Docker Cloud console. Let's go over to the left menu and click on stacks. Now click on Create. We're going to want to name our stack. We're going to be creating a WordPress stack so we'll name our stack WordPress.
Our WordPress stack will require two services. WordPress and MySQL. Two spaces in we're going to want to tell it what image to use. After WordPress, we put a colon in, and then the tag we're going to use. In this case, we're using latest. And then we're going to want to do the same thing for MySQL. Next we need to create a links section. This is going to be a YAML array.
We're going to use spaces here. We're creating a link from the MySQL service to the WordPress service. This will share all the environment variables from MySQL to WordPress. So WordPress will know how to log in to MySQL. Next we're going to need to create the configuration for WordPress. This is all done through a series of environment variables, eight of them. Two spaces in and two more, a dash, WordPress, underscore.
All these environment variables have to do with authentication. We're going to set them all to secret, but you should set them all to something else. These all need to be quoted. You can find the documentation for all of these variables on Docker Hub, the read me for the WordPress container. Next we need to add a port section to the WordPress service.
Two spaces in, ports, and this is another YAML array. We're going to be mapping port 80 from the outside to port 80 on the inside. Now we need to add our environment variable for MySQL. This is the same environment variable we added for the MySQL service when we created it before. But this time we're setting the password to WordPress test.
And this also needs to be quoted. Now we can click Create or Create & Deploy. If we click Create, it'll create the stack, but not start it. If we click Create & Deploy, it'll create the stack and then deploy the services. Let's go ahead and click Create & Deploy. And we can see the service starting up. MySQL's starting first, because WordPress is linked to MySQL. And now WordPress is starting.
And there, we've done it. In the next video, we'll manage this stack we've just deployed.
- Linking to cloud providers
- Creating a node cluster
- Creating and scaling a service
- Installing, setting up, and using the CLI tool
- Creating a basic stack file and managing a stack
- Pushing a container image
- Linking containers in Docker Cloud
- Linking containers for service discovery