skip to Main Content

I have been working on a FastAI model and am now ready to deploy it. However, I’m facing difficulties in getting the model to work via Docker locally.

I’m at a loss as to what’s causing the problem and how to resolve it. I’ve little experience with Docker. Creating my own Dockerfile is new to me; so I may have left out obvious commands.

Dockerfile:

# Install image and dependencies
FROM python:3.9

# Set working directory
WORKDIR /app

# Copy the application files from the host to the container
COPY app.py /app/

# Install necessary packages
RUN apt-get update && 
    apt-get install -y --fix-missing && 
    pip install pip==20.2

# Install project dependencies
COPY requirements.txt /requirements.txt
RUN pip install -r /requirements.txt

# Download model artefacts from S3
RUN apt-get install -y awscli 
    && mkdir -p /models/ 
    && aws s3 cp s3://foo.pkl /models/ 
    && aws s3 cp s3://bar.pth /models/

# Expose the port
EXPOSE 8000

# Run the application
CMD ["python", "/app/app.py"]

# docker run -p 8000:8000 my_image

Traceback:

Step 7/9 : RUN apt-get install -y awscli     && mkdir -p /models/     && aws s3 cp s3://foo/bar.pkl /models/     && aws s3 cp s3://foo/bar.pth /models/
 ---> Running in 7b2d18a2957a
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
...
[Errno 13] Permission denied: '/usr/lib/python3/dist-packages/pkg_resources/__pycache__/__init__.cpython-39.pyc.140347841853312'
...
E: Sub-process /usr/bin/dpkg returned an error code (1)
The command '/bin/sh -c apt-get install -y awscli     && mkdir -p /models/     && aws s3 cp s3://foo.pkl /models/     && aws s3 cp s3://bar.pth /models/' returned a non-zero code: 100

Many of these occur: [Errno 13] Permission denied


Inserting user before failing Step didn’t work:

# Create a new user
RUN useradd -m -s /bin/bash user

# Give newuser all privileges
RUN usermod -aG sudo user

# Switch to user
USER user

Traceback:

Step 10/12 : RUN apt-get install -y awscli     && mkdir -p /models/     && aws s3 cp s3://foo.pkl /models/     && aws s3 cp s3://bar.pth /models/
 ---> Running in 96d1e6f73307
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
The command '/bin/sh -c apt-get install -y awscli     && mkdir -p /models/     && aws s3 cp s3://foo.pkl /models/     && aws s3 cp s3://bar.pth /models/' returned a non-zero code: 100

2

Answers


  1. I just had this problem on my Ubuntu system while installing python3.6.

    I found this discussion on the docker forum, which basically states, that having installed docker as snap creates this problem. The discussion suggests, that snap and the storage driver overlay2 are not working correctly together.

    I removed the docker snap via

    sudo snap remove docker
    

    and then followed the official install guide from Docker for Ubuntu systems. Note, that I did not select the desktop version, since that seems to do something weird with VMs, like it works on Windows. I selected the Ubuntu server guide, though I’m using it on my Ubuntu desktop.

    The installation of packages via apt-get is now working correctly and without errors.


    The alternative mentioned in the discussion – which I didn’t try – is to set your Docker daemon to use vfs as storage driver. I’m copying the corresponding instructions from Paul Larsons post there:

    • edit /var/snap/docker/current/config/daemon.json and replace “overlay2” with “vfs” for the storage-driver
    • run sudo snap restart docker
    Login or Signup to reply.
  2. To resolve this issue, you can add the USER command to your Dockerfile to switch to the root user before running the command that requires elevated privileges. Here is an example:

    FROM ubuntu
    
    # Switch to root user
    USER root
    RUN apt-get update
    
    # Switch back to non-root user
    USER nonrootuser
    

    Or you can add the "sudo" with your commands like "sudo apt-get update"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search