Search code examples
node.jsdockerdocker-registry

How to specify Docker private registry credentials in Docker configuration File?


I am creating Docker container of nodejs application. Below is the sample of my Docker configuration file

FROM node:6.11
WORKDIR /usr/src/app
COPY package.json .
npm install
copy . /usr/src/app
EXPOSE 80
CMD [ "npm", "start" ]

This will download the node image from Docker hub and then it will create Docker image as per the configuration.

For security reasons I don't want to download nodejs image from Docker hub, Instead I want to use my private repository to download nodejs image.

As I have setup private repository I am not sure how to specify registry credentials in DockerFile.

Can anyone help me with this?


Solution

  • By default, docker pulls all images from Dockerhub. If you want to pull an image from another registry, you have to prefix the image name with the registry URL. Check the official docker pull documentation.

    In your case, you have 2 options:

    The first is to specify explicitly the registry inside the Dockerfile as such:

    FROM <registry>:<port>/node:6.11
    WORKDIR /usr/src/app
    

    Once you build, the image will be downloaded from the private registry. Make sure that you are logged in to the registry before building using the docker login command.

    Alternatively, if you don't want to change the docker file. Pull the image from the private registry using docker pull <registry>:<port>/node:6.11 and then force docker build to use this image by tagging it with only node:6.11

    docker tag <registry>:<port>/node:6.11 node:6.11