My operating system is Ubuntu. I am also only using the cli and not a graphical environment.
I am testing my first compose .yml file. What are the differences between docker-compose and “docker compose”? Is docker-compose deprecated?
I am looking at the official documentation from docker, and the requirements look different for each command. If I understand this correctly, docker-compose only requires a functioning docker environment (apt install docker) and the .yml file (in my configuration I have already pulled all relevant images ie. docker pull imagename, and these docker images are tested and working). However, the documentation for “docker compose” looks like the requirements are the docker installation, a docker file, and a compose .yml file.
So is docker-compose fully deprecated and replaced with “docker compose”? Are both commands still in use depending on environment?
Does docker-compose also require a docker file, or does it only need a functioning docker environment and the .yml file?
I am following a tutorial for joplin/server. This tutorial was published in July 2022, uses docker-compose, only uses a .yml file and does not mention a docker file.
It seems you misinterpreted the documentation. The only requuirement of Docker Compose is docker since docker compose is another client for Docker which let’s you define everything in a yaml file. Compose v1 was originally written in Python, so you could install it in a Python virtual environment. Compose v2 was written in Go but for the same purpose.
I guess you found different examples for v1 and v2 but both versions can help you build a Docker image which requires a Dockerfile usually. v2 also supports the
dockerfile_inline option so you can write the content of the Dockerfile there. It is not a requirement of any compose. It is used by Docker to build an image and you can define that too in the compose file. Compose v2 also ignores the version keyword in the compose file.
Regarding the filename, since Compose v2 is a plugin for Docker, you can use it as
docker compose, but you could easily add an alias to that command as
docker-compose which was how the command of Compose v1 was named.
Usually you can follow a tutorial written for compose v1 and use
docker compose instead of
I have a tutorial too in which I write about compose as well: Welcome to Learn Docker’s documentation! — Learn Docker documentation
I wrote it for compose v1. When I rewrote it for v2 I basically just replaced all
docker-compose commands with
docker compose and removed the version keyword from the compose files.
There are some features though that compose v2 doesn’t support. I wrote about one here: Docker Compose volumes, volume-only projects and init containers - DEV Community
You can read about other differences in the documentation:
Ok. Thank you. That helps.
I still have a question. I don’t see the universal requirement for the Dockerfile. In my environment everything is already configured, but docker compose still expects the Dockerfile. Is it suitable to write a Dockerfile like this:
RUN apt update
given my environment is already configured?
If by requirement for a Dockerfile you mean the syntax and the minimum content, there are a lot of examples on the internet and in the documentation and in my tutorial which I linked in my previous comment. Just by searching for “Dockerfile” on Google you find out everything in the first results. For example: Best practices for writing Dockerfiles | Docker Docs
In short: A container is an isolated environment with its own filesystem, so you need to choose a base image. like:
Then you can use
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl
A Dockerfile is only needed if
build: is configured in the compose file. Most compose files are rather used to create containers from existing images from a registry, than to build images locally and run those.
Do you mind sharing your compose file, so we can see what you actually configured?
This is a minimal example to create a nginx container: