Home > Enterprise >  Unable to build a docker image following Docker Tutorial
Unable to build a docker image following Docker Tutorial

Time:10-07

I was following this tutorial on a Macbook to build a sample Docker image but when I tried to run the following command:

docker build -t getting-started .

I got the following error:

[ ] Building 3.2s (15/24)                                                                                                                                                                                                                                                        
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                        0.0s
 => => transferring dockerfile: 1.05kB                                                                                                                                                                                                                                      0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                           0.0s
 => => transferring context: 34B                                                                                                                                                                                                                                            0.0s
 => [internal] load metadata for docker.io/library/nginx:alpine                                                                                                                                                                                                             2.7s
 => [internal] load metadata for docker.io/library/python:alpine                                                                                                                                                                                                            2.7s
 => [internal] load metadata for docker.io/library/node:12-alpine                                                                                                                                                                                                           2.7s
 => [internal] load build context                                                                                                                                                                                                                                           0.0s
 => => transferring context: 7.76kB                                                                                                                                                                                                                                         0.0s
 => [base 1/4] FROM docker.io/library/python:alpine@sha256:94cfb962c71da780c5f3d34c6e9d1e01702b8be1edd2d450c24aead4774aeefc                                                                                                                                                 0.0s
 => => resolve docker.io/library/python:alpine@sha256:94cfb962c71da780c5f3d34c6e9d1e01702b8be1edd2d450c24aead4774aeefc                                                                                                                                                      0.0s
 => CACHED [stage-5 1/3] FROM docker.io/library/nginx:alpine@sha256:686aac2769fd6e7bab67663fd38750c135b72d993d0bb0a942ab02ef647fc9c3                                                                                                                                        0.0s
 => CACHED [app-base 1/8] FROM docker.io/library/node:12-alpine@sha256:1ea5900145028957ec0e7b7e590ac677797fa8962ccec4e73188092f7bc14da5                                                                                                                                     0.0s
 => CANCELED [app-base 2/8] RUN apk add --no-cache python g   make                                                                                                                                                                                                          0.5s
 => CACHED [base 2/4] WORKDIR /app                                                                                                                                                                                                                                          0.0s
 => CACHED [base 3/4] COPY requirements.txt .                                                                                                                                                                                                                               0.0s
 => CACHED [base 4/4] RUN pip install -r requirements.txt                                                                                                                                                                                                                   0.0s
 => CACHED [build 1/2] COPY . .                                                                                                                                                                                                                                             0.0s
 => ERROR [build 2/2] RUN mkdocs build                                                                                                                                                                                                                                      0.4s
------                                                                                                                                                                                                                                                                           
 > [build 2/2] RUN mkdocs build:
#23 0.378 Traceback (most recent call last):
#23 0.378   File "/usr/local/bin/mkdocs", line 5, in <module>
#23 0.378     from mkdocs.__main__ import cli
#23 0.378   File "/usr/local/lib/python3.10/site-packages/mkdocs/__main__.py", line 14, in <module>
#23 0.378     from mkdocs import config
#23 0.378   File "/usr/local/lib/python3.10/site-packages/mkdocs/config/__init__.py", line 2, in <module>
#23 0.378     from mkdocs.config.defaults import DEFAULT_SCHEMA
#23 0.378   File "/usr/local/lib/python3.10/site-packages/mkdocs/config/defaults.py", line 4, in <module>
#23 0.378     from mkdocs.config import config_options
#23 0.378   File "/usr/local/lib/python3.10/site-packages/mkdocs/config/config_options.py", line 5, in <module>
#23 0.378     from collections import Sequence, namedtuple
#23 0.378 ImportError: cannot import name 'Sequence' from 'collections' (/usr/local/lib/python3.10/collections/__init__.py)
------
executor failed running [/bin/sh -c mkdocs build]: exit code: 1

The Dockerfile I used:

# syntax=docker/dockerfile:1
FROM node:12-alpine
RUN apk add --no-cache python g   make
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]

The sample app is from: https://github.com/docker/getting-started/tree/master/app

I'm pretty new to Docker and would appreciate if someone could help point out how I can get this working.

Solutions:

It turns out there were two issues here:

  1. I should have run the docker build -t getting-started . command from the /app folder where my newly-created Dockerfile is located. In my test, I ran the command from the root folder where there was a different Dockerfile as @HansKilian pointed out. Once I tried it inside the /app folder, it worked fine.

  2. The problem with the Docker file in the root folder is caused by a Python version mismatch issue, as pointed out by @atline in the answer. Once I made the change as suggested, I could also build an image using that Dockerfile.

Thank you both for your help.

CodePudding user response:

See its Dockerfile, it uses FROM python:alpine AS base, which means it used a shared tag. Another word, at the time the document wrote, python:alpine means maybe python:3.9-alpine or others.

But now, it means python:3.10-alpine, see this.

The problems happens at mkdocs itself, it uses next code:

from collections import Sequence, namedtuple

But, if you have a import for above in a python3.9 environment, you will see next, which tell you it will stop working from python3.10:

$ docker run --rm -it python:3.9-alpine /bin/sh
/ # python
Python 3.9.7 (default, Aug 31 2021, 19:01:35)
[GCC 10.3.1 20210424] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from collections import Sequence
<stdin>:1: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working

So, for you, to make the guide works again for you, you need to change FROM python:alpine AS base to:

FROM python:3.9-alpine AS base

  • Related