Group permission – docker compose not working

If you got to this article, you probably ran the docker-compose command, and errors came up. So we addressed the permission error related to the docker group in Linux.

Often the user lacks permission for a specific task to be performed on his machine. With docker, it is no different, and we came across this error when using docker and docker-compose for the first time.

In our case, the .yml file configuration was correct. However, we could not start the container with the image defined in our docker-compose file.

The problem was in the definition of our Linux groups. So, yes, this tutorial is for Linux users. Soon we will be making it available for Windows as well.

There are several groups in our machine. One of them should be the docker group (if you have it installed). Consequently, in order to create the container from docker-compose, we need permission. Therefore, we must add our user to the docker group.

Initially, we must first verify if the docker group exists. To do this, run the command below in the terminal.

sudo group

A list of all your groups will be returned, as shown in the figure below.

adding user to docker group

If the group does not exist, use the command below to create it. Remember, to create groups and define users, we must have permission or use the sudo command. Otherwise, we will get the error “permission denied”.

sudo groupadd docker

To add your user to the docker group, run the command below modifying the parameter. The command uses -a (add) -G (group) to add the to the specified group (docker).

sudo usermod -a -G docker <user>

Later confirms that your user has been added to the group

sudo groups <user>

Ready! If your problem was just permissions you will be able to start the docker container via docker-compose.

See more posts from our Docker tutorial

Article 01 – Docker Installation

Article 02 – Docker: Handling Containers

Article 03 – Portainer : Installation and Configuration

Juliana Mascarenhas
Juliana Mascarenhas

Data Scientist and Master in Computer Modeling by LNCC.