Create and publish docker image

Anton Lytvynov
2 min readJun 4, 2020

Push simple Node application to Docker hub

Build image

Dockerfile example https://github.com/alytvynov/docker-simple-node/blob/master/Dockerfile

# Start from a Node.js 10 (LTS) image
FROM node:10

# Specify the directory inside the image in which all commands will run
WORKDIR /usr/src/app

# Copy package files and install dependencies
COPY package*.json ./
RUN
npm install
RUN npm install --save express

# Copy all of the app files into the image
COPY . .

# The default command to run when starting the container
CMD [ "npm", "start" ]

To build image run the command

docker build -t simple-node .

Now if you run the command bellow you ll see your image

docker images
Simple-node image

Docker hubs

What is docker image registry ? This is the place where you can save your images and their version. Like GitHub, GitLab, Bitbucket, there are also different docker hubs.

Sure the most popular is Docker hub. But the most modern companies provides their own image registries.

Docker login

To publish image to registry you should have credentials there. Than login throw the terminal. https://docs.docker.com/engine/reference/commandline/login/

So open your terminal enter

docker login

Publish image

To publish the image we need to create a tag and than push it.

In the example bellow we ll push image to latest and 0.0.1.

#without version
docker tag simple-node lytvynov/simple-node
docker push lytvynov/simple-node
#with version
docker tag simple-node lytvynov/simple-node:0.0.1
docker push lytvynov/simple-node:0.0.1

Than you ll see two versions in your hub account.

Published images

Thank you for your attention.

Thank you for your attention.

Do you need help with web or mobile development? Feel free to contact me here.

P.S. I really appreciate your like or share 🙏.

--

--

Anton Lytvynov

CEO & Founder of Lytvynov Production, Senior web developer, architect, cryptocurrencies trader, https://lytvynov-production.com