Deploying Docker containers


There are many ways to deploy containers but we will be focussing on Docker Compose.

Deploying with Docker Compose

Docker Composeopen in new window makes it easier and a lot more clear to deploy Docker containers.

In this was the previous command to deploy MySQL:

docker run --name mysql -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=abc123 -v mysql_data_container:/var/lib/mysql mysql:8

Becomes the following in a docker-compose.yml file:

version: "3.9"
services:
  mysql:
    image: "mysql:8"
    environment:
      MYSQL_ROOT_PASSWORD: abc123
    ports:
      - "3306:3306"
    volumes:
      - mysql_data_container:/var/lib/mysql

volumes:
 mysql_data_container:

The first version: "3.9" line corresponds to the Compose file versions which supports Docker releasesopen in new window. Notice that you create the Docker Volumes seperately as well.

To deploy our example Docker image we can use the following docker-compose.yml file:

version: "3.9"
services:
 randomizer-service:
  image: miverboven/python-api-test
  ports:
    - "8000:8000"

Notice that we need to include the ports that we need to open, declared back in our Dockerfile.

We can then run these Docker Compose files to deploy them as local Docker containers, similarly to using plain Docker commands. Navigate to the directory which holds your docker-compose.yml file and run:

docker compose up

Deploying to Okteto Cloud

Docker Compose can not only be used to deploy locally, but is also a tool in many different deployment environments. One of those is Okteto Cloudopen in new window, which has a generous free offering for developers.

After navigating to cloud.okteto.com and logging in via GitHub you are granted access to you own cloud Kubernetes environment. Using the following button you can launch a development environment based on a docker-compose.yml file.

Okteto launch dev

We can select the option to deploy from a GitHub repository, which means that you need to have a GitHub repository available that holds a docker-compose.yml file in the root of the repository:

Okteto launch from git

Besides that there are many other options, such as deploying from a Kubernetes file, HELM charts, ...

In this case we have deployed the following docker-compose.yml file:

version: "3.9"
services:
 randomizer-service:
  image: miverboven/python-api-test
  ports:
    - "8000:8000"

This will result in a deployment being up and running like this:

Deployment

Notice that you also get an available endpoint to test. If everything went well you should be able to send a GET request using Postman, the browser, ... to:

https://<SERVICE NAME>-<OKTETO ACCOUNT NAME>.cloud.okteto.net/percentage
Last update: 10/27/2022, 1:52:20 PM