Understanding Docker step-2

coktopus profile image coktopus ・2 min read


Docker is all about containerization. It is an open-source project used to run containerized applications.

Containers are isolated platform in which applications run independently.

Alt Text

All the dependencies, npms, environment variables, network ports or anything required to run the application can be added to the container with the help of Dockerfile to run the docker images which is the build image of the application.

The application running in the container can be accessed from outside the container if exposed.

FROM node:11.8.0-alpine

WORKDIR */usr/src/app*

COPY *package.json* *.*

RUN *npm* *install*

copy *.* *.*

EXPOSE *3100*

CMD "node" "server.js"

Dockerfile is a synchronized set of command written in an easy-to-understand syntax that includes the instructions to build a Docker image.

Dockerhub is a public repository and can be used to pull and push images publicly. There are plenty of official images like node. Many private repository/registries are available and GCR is the one which is being used in this series.

To build the image:

docker build ${url of dockerfile}

To expose the application running in the container, a mapping of inter-port and external port is required.

docker run [OPTIONS] ${internal-port}:${external-port} ${IMAGE ID}

After building the image, image id will be available in images list.:

Alt Text

After running the container, container id will be available:

Alt Text

Few docker commands

'docker ps' - list of running container

'docker' - list of images

'docker run' - to run the image

'docker rm' - to remove resource image/container

'docker build' - to build for dockerfile

video of complete setup and implementation of docker

For Gcloud setup --> https://www.youtube.com/watch?v=A-3yY594Oko&t=27s


Editor guide