Getting Started with Docker

Docker I use it for business, but I don't think I understand the mechanism so deeply, so Let's start with the basics.

What is a container in the first place?

Contrast with virtualization

Operation level kernel Remarks
Virtualization OS Uses a unique kernel for each VM It emulates HW using a hypervisor and runs multiple OSs, so processing is heavy.
container process Share host OS kernel The process is light because it is a process rather than running the OS

Specifically, processes are isolated using kernel functions such as Namespace and cgroup. (Details in the future)

In other words, because it is light, you can easily deploy apps.

What is Docker

The platform that runs the container. You can build and run applications in containers, or distribute containers (Docker images, Dockerfiles).



--CentOS7 on Vagrant

#Remove if you have an older version of Docker installed
[[email protected] ~]$ sudo yum remove docker*

#Add docker repository
[[email protected] ~]$ sudo yum install -y yum-utils
[[email protected] ~]$ sudo yum-config-manager --add-repo

# docker-ce-Make sure the stable repository is enabled
[[email protected] ~]$ cat /etc/yum.repos.d/docker-ce.repo

#Package update
[[email protected] ~]$ sudo yum -y update

#Latest installation of Docker Engine and containerd
[[email protected] ~]$ sudo yum -y install docker-ce docker-ce-cli

#Version confirmation
[[email protected] ~]$ docker -v
Docker version 20.10.1, build 831ebea

#Start Docker
[[email protected] ~]$ sudo systemctl start docker

# hello-Download and run world Image
[[email protected] ~]$ sudo docker run hello-world
~ Omitted ~
#Success if this is displayed
Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:

For more examples and ideas, visit:

Post-installation work

#Make sure the docker group is created when you install docker
[[email protected] ~]$ cat /etc/group | grep docker

#Add current user to docker group
[[email protected] ~]$ echo $USER
[[email protected] ~]$ sudo usermod -aG docker $USER

#Reflection of changes
[[email protected] ~]$ newgrp docker
[[email protected] ~]$ id
uid=1000(vagrant) gid=993(docker) groups=993(docker),1000(vagrant) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

#Confirm that the container can be started without sudo
[[email protected] ~]$ docker run hello-world

tutorial Dockerfile A file that predefines what to do inside the container. If you write the definition for connecting to system resources such as network in this file, The same environment can be shared by multiple users.

Run sample application

#Clone sample application from github
[[email protected] ~]$ sudo yum -y install git
[[email protected] ~]$ git clone
[[email protected] ~]$ cd node-bulletin-board/bulletin-board-app/
#There is a Dockerfile!
[[email protected] bulletin-board-app]$ ls
app.js  backend  Dockerfile  fonts  index.html  LICENSE  package.json  server.js  site.css
[[email protected] bulletin-board-app]$
#Check the contents
[[email protected] bulletin-board-app]$ cat Dockerfile 
FROM node:current-slim

WORKDIR /usr/src/app
COPY package.json .
RUN npm install

CMD [ "npm", "start" ]

COPY . .
#Create an image!--tags is an option to name the image
[[email protected] bulletin-board-app]$ docker build --tag bulletinboard:1.0 .
\Sending build context to Docker daemon  45.57kB
Step 1/7 : FROM node:current-slim
current-slim: Pulling from library/node
e50c3c9ef5a2: Pull complete 
7d035f3b6068: Pull complete 
1758a95126e3: Pull complete 
d39676814e5a: Pull complete 
e7aa22215d06: Pull complete 
Digest: sha256:7bf36131ed121f8113794e83a665bdf5d81cdf77c07672a6c1620fd71675bc8c
Status: Downloaded newer image for node:current-slim
 ---> 9ac9e9f30b2c
Step 2/7 : WORKDIR /usr/src/app
 ---> Running in ab0034727068
Removing intermediate container ab0034727068
 ---> 2c6dc642d528
Step 3/7 : COPY package.json .
 ---> 8ee0076c51cb

~ Omitted ~

 Step 7/7 : COPY . .
 ---> e614dbf84475
Successfully built e614dbf84475
Successfully tagged bulletinboard:1.0
[[email protected] bulletin-board-app]$
#Run the created image as a container
[[email protected] bulletin-board-app]$ docker run --publish 8000:8080 --detach --name bb bulletinboard:1.0

Explanation of the executed command

docker run --publish 8000:8080 --detach --name bb bulletinboard:1.0

command meaning
run Container execution
--publish Specifying port forwarding
Unless specified, communication is rejected by default.
--detach Run the container in the background and display the container ID
If this is not specified, the prompt in the container will be displayed.
--name Container name

Since the container has started, try connecting to http: // localhost: 8000 with a browser

When you are satisfied, delete the container. Since the running container cannot be deleted suddenly, stop it and then delete it.

[[email protected] bulletin-board-app]$ docker stop bb
[[email protected] bulletin-board-app]$ docker rm bb

That's all for now. If you write out the contents of the Dockerfile and so on, one more article is not enough. It seems that the first post will not be possible forever without separating it somewhere, so I will separate it here.

Recommended Posts

Getting Started with Docker
[Google Cloud] Getting Started with Docker
Getting Started with Docker with VS Code
Getting Started with DBUnit
Getting Started with Ruby
Getting Started with Swift
Getting Started with Doma-Transactions
Getting Started with Docker for Mac (Installation)
Getting Started with Doma-Annotation Processing
Getting Started with Java Collection
Get started with DynamoDB with docker
Getting Started with JSP & Servlet
Getting Started with Java Basics
Getting Started with Spring Boot
Getting Started with Ruby Modules
Getting Started with Java_Chapter 5_Practice Exercises 5_4
Getting started with Java lambda expressions
Proceed with Rust official documentation on Docker container (1. Getting started)
Getting Started with GitHub Container Registry instead of Docker Hub
Getting Started with Ruby for Java Engineers
Getting Started with Parameterization Testing in JUnit
Getting Started with Java Starting from 0 Part 1
Getting Started with Ratpack (4)-Routing & Static Content
Getting started with the JVM's GC mechanism
Getting Started with Language Server Protocol with LSP4J
Getting Started with Creating Resource Bundles with ListResoueceBundle
Getting Started with Java_Chapter 8_About Instances and Classes
Links & memos for getting started with Java (for myself)
Launch MariaDB with Docker
Getting Started with Doma-Using Projection with the Criteira API
Rails deploy with Docker
Run Pico with docker
Explode Docker with WSL2
Use Puphpeteer with Docker
Getting Started with Doma-Using Subqueries with the Criteria API
Getting Started with Java 1 Putting together similar things
Operate Emby with Docker
Try WildFly with Docker
Use ngrok with Docker
Getting started with Kotlin to send to Java developers
Run Payara with Docker
Maybe it works! Let's get started with Docker!
[Docker] Connection with MySQL
Getting Started with Doma-Using Joins with the Criteira API
Php settings with Docker
Getting Started with Doma-Introduction to the Criteria API
Get started with Gradle
Disposable PHP with Docker
Install Composer with Docker
I tried Getting Started with Gradle on Heroku
Getting started with Java programs using Visual Studio Code
Getting Started with Legacy Java Engineers (Stream + Lambda Expression)
Pytorch execution environment with Docker
Use GDAL with Python with Docker
Deploy with EC2 / Docker / Laravel
Run TAO Core with Docker
Docker management with VS Code
Get started with Spring boot
Set up GitLab with docker
Run Rails whenever with docker
[Docker] Rails 5.2 environment construction with docker