Home > Software design >  Dive into the Dockerfile of nginx parent image
Dive into the Dockerfile of nginx parent image

Time:06-11

I am trying to understand the Dockerfile of nginx official Docker image. I am focusing on the following lines:

COPY docker-entrypoint.sh /
COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d

I am playing locally with Docker Desktop. If my Dockerfile has only the following line:

FROM nginx

and building my own nginx image, then what is the build context for the Dockerfile of nginx Docker image? My issue is I cannot understand where the files:

docker-entrypoint.sh
10-listen-on-ipv6-by-default.sh

are living and where are they copied from?

Same question is applied to Ubuntu image

CodePudding user response:

The build context is always the directory you give to the build command, and it usually contains the Dockerfile directly in that directory.

docker build ./build-context-directory
# Docker Compose syntax
build: ./build-context-directory
build:
  context: ./build-context-directory

The two important things about the context directory are that it is transferred to the Docker daemon as the first step of the build process, and you can never COPY or ADD anything outside the context directory into the image (excepting ADD's ability to download URLs).

When your Dockerfile starts with a FROM line

FROM nginx

Docker includes a pre-built binary copy of that image as the base of your image. It does not repeat the steps in the original Dockerfile, and you do not need the build-context directory of that image to build a new image based on it.

So a typical Nginx-based image hosting only static files might look like

FROM nginx
COPY index.html /usr/share/nginx/html
COPY static/ /usr/share/nginx/html/static/
# Get EXPOSE, ENTRYPOINT, CMD from base image; no need to repeat them

which you can run with only your application's HTML content but not any of the Nginx-specific details you quote in the question.

  • Related