[Docker] lesson 12 < section 6 (Running Multi-container Applications) - simple solution

I just had to add
user: root
in the docker-compose.yml file
It seems like docker-compose.yml file is executing the backend host as the user set in this Dockerfile and by adding user: root it knows to run it like root and not app.
The good news is that we do not give the permission x to the file as was intended in the first place. Do the docker exec -it … sh to the backend container and see for yourself

version: "3.8"

services:
  frontend:
    depends_on: 
      - backend
    build: ./frontend
    ports:
      - 3000:3000

  backend: 
    depends_on: 
      - db
    build: ./backend
    user: root
    ports: 
      - 3001:3001
    environment: 
      DB_URL: mongodb://db/vidly
    command: ./docker-entrypoint.sh

  db:
    image: mongo:4.0-xenial
    ports:
      - 27017:27017
    volumes:
      - vidly:/data/db

volumes:
  vidly:

Hi,
I did not take the course on Docker from Mos so I don’t know the context.
Reading your post it looks like Mosh is doing an operation to give permission to a (set of) file(s) and you decided to use the root user instead.

That’s not very good news then. The philosophy in Linux is to avoid root at all cost, hence the chmod +x kind of operation.

That said, many docker images I used break that rule anyway.

You are right. I was not thinking straight.
I should have done the whoami command when doing docker exec -it … sh in backend.
However, chmod +x didnt work for me the first time around. I was totally stuck. Whats even weirder is that a few days later I dont even need the chmod to put permission x on ‘others’ (and I removed all images and containers and ran --no-cache when building).
Glad it works but also a bit worried not knowing what caused the error the first time around.

1 Like