0

There are a lot of applications which I launch on my workstation using docker-compose up.

Reasons:

  • They don't have an installer, or I don't want to use it
  • They require a dedicated storage engine to be present
  • They require a build process step
  • They are created by me and I want them to be easily launched on any workstation
  • e.t.c

So what I usually end up with the following file-structure:

myAppDir
  - docker-compose.yml
  - Dockerfile (not always)
  - someConfigFile

And my docker-compose.yml is something like this: (It can contain 2 or 3 services, but I provide the simplest form that I use)

version: '3.7'
services:
  mysql:
    image: mysql:5.7.29
    restart: always
    volumes:
      - ./mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
    environment:
      - MYSQL_ROOT_PASSWORD=xyz
    ports:
      - 3306:3306

Then when I need to launch the application I just perform:

docker-compose up # (or with --build)

Recently I tried to add:

    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 200M

and got a message:

Some services (mysql) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use docker stack deploy to deploy to a swarm.

So I tried:

docker stack deploy mystack --compose-file docker-compose.yml

and got message:

Ignoring unsupported options: restart

this node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again

This seems more complex that docker-compose up.
I saw that I can use --compatibility flag e.g.

docker-compose --compatibility up

But the word compatibility means to me that I should soon switch to a new way of launching my apps locally.

My question is: What is the new procedure that I should follow for launching apps on my workstation using a docker and a descriptor file, in order to support options present in Compose file v3?

Marinos An
  • 9,481
  • 6
  • 63
  • 96

2 Answers2

1

If you want to specify memory limits and similar constraints for local containers, you need to use a version 2 Compose file. This is called out in the documentation for the deploy: resources: section. docker/compose#4513 has some reasonably clear statements that Compose file version 2 is more targeted at local setups and version 3 more at Swarm installations, and that Docker intends to keep supporting both file versions.

Docker has put many options and functions specific to their Swarm cluster-installation mode into the core product. Anything that mentions a "stack", for example, is specific to a Swarm setup. One consequence of Swarm and plain-Docker things being combined together is that the deploy: Docker Compose options only have an effect in Swarm mode. The documentation for the deploy: key notes:

This only takes effect when deploying to a swarm with docker stack deploy, and is ignored by docker-compose up and docker-compose run.

David Maze
  • 130,717
  • 29
  • 175
  • 215
0

My question is: What is the new procedure that I should follow for launching apps on my workstation using a docker and a descriptor file, in order to support options present in Compose file v3?

Docker compose V3 is meant to be used with Docker Swarm deployments, therefore you need to run your Docker in Swarm mode, otherwise just keep using the V2 and it's simpler interface for localhost developments.

For example restart is ignored because that responsibility belongs now to the Docker Swarm, not to Docker itself.

Using the compatibility flag it's kind of converting at runtime your V3 compose file into a V2 compose file.

So in short just use V3 if you want to run Docker in Swarm mode to take advantage of all its new features, aka it's kind of a Kubernetes in Docker land.

Exadra37
  • 11,244
  • 3
  • 43
  • 57