4

I'm quite new to networking and server management so thank you in advance for your patience.

Currently I am learning how to build a docker image on AWS's Cloud9.

The tutorial I'm following is from AWS themselves and is named MythicalMysfits which is meant to walk a new user through the main tools used on AWS to build a modern web application.

I'm currently on step 2, building a dynamic website:

https://aws.amazon.com/getting-started/hands-on/build-modern-app-fargate-lambda-dynamodb-python/module-two/

When I run the following command:

docker build . -t REPLACE_ME_AWS_ACCOUNT_ID.dkr.ecr.REPLACE_ME_REGION.amazonaws.com/mythicalmysfits/service:latest

I of course replace the two parts necessary with my account ID and region.

It prompts another file Named "Dockerfile" containing the following commands to be run:

FROM ubuntu:latest
RUN echo Updating existing packages, installing and upgrading python and pip.
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
RUN pip install --upgrade pip
RUN echo Copying the Mythical Mysfits Flask service into a service directory.
COPY ./service /MythicalMysfitsService
WORKDIR /MythicalMysfitsService
RUN echo Installing Python packages listed in requirements.txt
RUN pip install -r ./requirements.txt
RUN echo Starting python and starting the Flask service...
ENTRYPOINT ["python"]
CMD ["mythicalMysfitsService.py"]

At this point the code begins to run, however fails:

Sending build context to Docker daemon  14.85kB
Step 1/13 : FROM ubuntu:latest
 ---> 1d622ef86b13
Step 2/13 : RUN echo Updating existing packages, installing and upgrading python and pip.
 ---> Using cache
 ---> d5aa972842ca
Step 3/13 : RUN apt-get update -y
 ---> Using cache
 ---> 56374a45d258
Step 4/13 : RUN apt-get install -y python-pip python-dev build-essential
 ---> Running in 3ce71d802d94
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package python-pip
The command '/bin/sh -c apt-get install -y python-pip python-dev build-essential' returned a non-zero code: 100

I understand that external to this document, apt-get does not work in Cloud9's IDE so I managed to install the python packages manually using sudo yum. I've spend a few hours over two days now trying to figure it out. I'm also in the correct directory as the tutorial advises.

Do you have any idea as to why the "Dockerfile" is misbehaving?

I thank you again for your time.

amx5
  • 43
  • 3

3 Answers3

4

I'm also following same tutorial. I had same issue than you.

I solved it by :

  • Using python3-pip instead of python-pi
  • Using pip3 instead of pip

In Docker file you just need to change following lines:

  • Replace line 4 by:

    RUN apt-get install -y python3-pip python-dev build-essential

  • Replace line 5 by:

    RUN pip3 install --upgrade pip

  • Replace line 10 by:

    RUN pip3 install -r ./requirements.txt

  • Replace line 12 by:

    ENTRYPOINT ["python3"]

Régis C.
  • 56
  • 1
1

I changed the first line of the Dockerfile from

FROM ubuntu:latest

to

FROM ubuntu:18.04

I cannot say whether this has any cost implications, though.

mschmidt
  • 11
  • 2
  • The issue is with the python version and not ubuntu. If changing to ubuntu:18.04 solved it for you, it was because ubuntu:18.04 had python 2.7 installed. It might work for the rest of the tutorial, but why not use the latest version when learning something new? – ahimsauzi Jun 02 '20 at 17:58
  • In my case, there were several follow-up errors when following the accepted python3 solution. – mschmidt Jun 04 '20 at 13:45
  • You are correct, about the subsequent python3 issue, however, using the same solution (changing the python call in question to python3 or pip3 depend on which line the error is) should solve the issue. Hope this helps. – ahimsauzi Jun 08 '20 at 18:25
0

As a general rule in writing dockerfiles: Can you execute the contents of each RUN line in sequence manually using the command line? This may give you valuable debugging information about where the failure lies.

It appears that apt-get is indeed working and python-pip should be available in Debian/Ubuntu repos.

Docker will sometimes behave in unexpected ways with the build cache especially after modifying a dockerfile and yours is failing after cached operations. The safest way to eliminate this possibility is to remove the cache by running:

docker images
docker rmi <image>

and remove the recent build attempt image to eliminate the cache

Peleion
  • 303
  • 1
  • 7
  • Thank you for your response, however it didn't change anything. I'll keep trying. I'll probably remove the environment and start again. – amx5 May 01 '20 at 08:41