본문 바로가기

Backend

Docker - Installation

반응형

To run your application globally, there are many things we have to set up from matching versions between each environment and configurations. Docket is a tool that allows us to manage the application in a container with all the necessary configurations. Docker is similar to a virtual machine in a sense that they both run on a virtual environment indepentantly from the major OS but docker runs on a container unit not the entire OS unit so it has a smaller size and faster than a virtual machine.

Go to the docker.com and you will see selected download option depending on your operating system. Click 'download' and run the installer when downloading is completed

After the installation is completed, restart the computer

A pop up will appear (If not click the docker launcher icon). Agree the term and you are ready to go

Verification

Run the command below to check if the installation was successful. If you see the server running, it is a green sign

docker version

Creating a Docker

Let's see how we can use docker, create a folder and open your editor. Then add a JavaScript file, write any random message to the console

Add 'Dockerfile' with no extension (If the editor asks you to add an extension, you can go a head and add it)

Dockerfile

Write the instruction that is needed to run the application in the file (this file is where all the magic happens).

 

First, specify basic image to use (docker has already made images for a variety of languages

FROM baseImage

You can check out the image list here

For example, you can use node.js image by specifying the verions followed by the language name

node:<version>


Specify a folder to store the image

COPY <from> <to>

(Optional) Specify the path where the application is stored. For example, if set '/app' in the <to> part above the path here will be '/app' (This is optional, you can specify the whole path in the running command instead)

WORKDIR <path>

Specify the run command

CMD <command>

This is a completed example of an instruction

FROM node:alpine
COPY . /app
WORKDIR /app
CMD node app.js

Build

Run the command below to build the docker

docker build -t <tagName> <location>

'tagName' is used to identify the image to run later. And 'location' is where the 'Dockerfile' is. Here it is on the root so I will use current path

docker build -t init .

Run

Run the command below to run the application

docker run <tagName>

Again 'init' is the <tagName> we use above

docker run init

You will see the message we wrote in the JavaScript file


How to Check the Image List

You can check the list of the images by running either of the commands below

docker images
docker image ls


Docker is a great tool that can spare you lots of headaches by automizing the confugurations and set ups needed for running your application.

 

References

Docker overview

 

Docker overview

 

docs.docker.com

 

728x90
반응형

'Backend' 카테고리의 다른 글

WSL Installation  (0) 2023.03.07
Internet Computer (Web 3) application  (0) 2023.03.07
Web 3 Application Deployment with Cycles Faucet  (3) 2023.03.04