Score:0

Problem with RUN command in Dockerfile on Ubuntu 22.04.1 LTS

gf flag

I am new with docker. I have the following Dockerfile and docker-compose.yml file

FROM python:3.9-alpine3.13

ENV PYTHONUNBUFFERED 1

COPY ./requirements.txt /tmp/requirements.txt
COPY ./app /app
WORKDIR /app
EXPOSE 8000

RUN python -m venv /py && \
    /py/bin/pip install --upgrade pip && \
    mkdir -p /vol/web/media && \
    mkdir -p /vol/web/static && \
    chown -R django-user:django-user /vol && \
    chmod -R 755 /vol && \
    
ENV PATH="/py/bin:$PATH"

USER django-user

and this docker-compose file

version: "3.3"

services:
  app:
    build:
      context: .
      args:
        - DEV=true
    container_name: app
    ports:
      - "8000:8000"
    volumes:
      - ./app:/app
      - data:/vol/web
    command: >
      sh -c "python manage.py migrate &&
             python manage.py runserver 0.0.0.0:8000"
  
    depends_on:
      - db

  db:
  ......

volumes:
  data:
  

I am a bit confused on how RUN instruction work.

  1. After running docker-compose build and docker-compose up commands, I have my container build. But my problem is, I accessed my app container by running $ docker exec -it app sh command, but inside I don't see /vol/web/media and /vol/web/static which for me are supposed to be created during the build of Dockerfile. Why I cannot find these two folders in my app container? where they are?

  2. When running RUN instructions in a Dockerfile to install for example some packages, where do that packages are installed? In my Ubuntu host machine or in the file system of container?

dummyuser avatar
uy flag
hi @Jules Betfien, 1) you mount the local directory `data` in your container to `/vol/web` this mount hides the directories `/vol/web/media` and `/vol/web/static` if you need these dierectories add them to the local data directory. 2) packages are installed in the container.
Jules Betfien avatar
gf flag
Thank you for your answer. I want to access /vol/web/ directory. When /vol/web/ directory is created by RUN instruction of dockerfile where is it situated? In the container?
dummyuser avatar
uy flag
if you create a directory within the dockerfile with RUN it is inside the container. you can see these directories if you remove the line `- data:/vol/web` from you docker compose file.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.