Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure docker-compose.yml to up a container as root

I'm trying to connect two containers with a docker-compose-yml, but it isn't working. This is my docker-compose.yml file:

version: "3" services:     datapower:         build: .         ports:             - "9090:9090"         depends_on:             - db     db:         image: "microsoft/mssql-server-linux:2017-latest"         environment:             SA_PASSWORD: "your_password"             ACCEPT_EULA: "Y"         ports:         - "1433:1433" 

When I make:

docker-compose up

This up my two containers. Then I stop one container and then I run the same container stoped independiently like:

docker-compose run -u root --name nameofcontainer 'name of container named in docker-compose.yml'

With this, the connection of the containers works. Exists a method to configure my docker-compose.yml to connect my containers like root without stop a container and run independently?

like image 720
Carlos Andres Avatar asked Feb 11 '18 02:02

Carlos Andres


People also ask

How do I execute a docker container as a root?

To do this, we use the docker exec command. The command above launches an interactive shell. It is good to ensure bash executable exists before the running command. As you can see, you have an interactive shell session where you can execute commands.

Does docker compose run as root?

By default that Unix socket is owned by the user root and other users can only access it using sudo. The Docker daemon always runs as the root user .

Is it OK to run container as root?

Running containers as root is a bad idea for security. This has been shown time and time again. Hackers find new ways of escaping out of the container, and that grants unfettered access to the host or Kubernetes node.

Do docker containers have root access?

Docker containers are designed to be accessed as root users to execute commands that non-root users can't execute.


1 Answers

Update:

There exists the user property that can be set in the compose file. This is documented in docker-compose file reference.

... services:     datapower:         build: .         user: root         ports:             - "9090:9090"         depends_on:             - db ... 
like image 107
yamenk Avatar answered Sep 27 '22 22:09

yamenk