Pages

Thursday, July 19, 2018

Building daycare website [Part 13]: Use docker-compose to simplify building and running Docker containers.

On my previous posts I described how to use Docker to create an image that can be used for development. On this post I will briefly talk about docker compose. If developers in your team are not too familiar with the docker CLI and your application gets more complex, it is useful to encapsulate all the parameters used to building and running the container(s) in a docker-compose file. Let's take a look at the file used to launch the development environment:

version: "3"
services:
  web:
    build:
      context: .
      dockerfile: Dockerfile.dev
    ports:
      - "5000:80"
    volumes:
      - .:/code/app

Notice that this file declares which Dockerfile to use when building and also maps the ports AND sets up the file volume. Now instead of remembering all those arguments to the 'docker run' command you can use the 'docker-compose' CLI that looks like this:

# builds the image
docker-compose build

# runs all the containers
docker-compose up

As we will see in a future blog post docker-compose can launch all the containers needed by your application in one short, easy to remember command.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.