[LINUX] Neat, whose employment has been postponed to Corona, has started Docker, so I will leave a personal note.

Introduction

After getting basic information at a vocational school, I went to a local town development and resort part-time job that I was interested in for about a year, and I was looking for an engineer job and doing job hunting ( From around March). However, due to the influence of the coronavirus, even if I get a job offer, I have been joining the company since July, and I have not been able to find a place where I can work most recently. So, as the title suggests, I am challenging Docker, thinking that I should improve my skills anyway. When I was a student, I mainly studied android application development, but I have a strong desire to come into contact with various technologies, so I wanted to start with a solid understanding of linuxOS. I hope I can take this opportunity to send out my learning records. Then thank you. I want to experience various things in practice as soon as possible. .. !!

Docker

the term

Docker Hub: A registry that manages Docker images as Github manages code Docker file: Design document for creating Docker image Docker image: Create container, distributeable Docker container: Virtual environment for actual development

Using Docker

Doker Login

$docker login

Doker image Pull

$docker pull {IMAGE name:TAG name}

Output example

$docker pull hello-world:latest
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:8e3114318a995a1ee497790535e7b88365222a21771ae7e53687ad76563e8e76
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest

Line 2: library points to Docker Hub Library https://hub.docker.com/u/library/

Check the local Docker Image

$docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              bf756fb1ae65        3 months ago        13.3kB
node                latest              a8d7efbae951        6 months ago        908MB

Creating a container

$docker run {IMAGE name}
//For run only, just create a container!
//If you want to continue working ↓
$docker run -it {IMAGE name:TAG name} bash
//If you want to specify more names
$docker run --name {Container name} -it {IMAGE name:TAG name} bash

Output example

$docker run hello-world

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.
    (amd64)
 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:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

Show container

$docker ps -a

Enter an existing container

$docker exec {Container name}
#To enter the container and start bash
$docker exec {Container name} -it bash

Exit the container

#In case of exit, the container is terminated, so a reboot is required to re-enter the container.
$exit
#Reboot
$docker restart {Container name or ID}

detach

If you don't want to keep the container running, use "ctrl + p + q" instead of the command attach

$docker attach {Container name/ID}

About deleting Docker Image and Container

Remove Docker Container

#Multiple specifications are possible
$docker rm {Container ID}

Remove Docker Image locally

⚠ Note that the image creating the container cannot be deleted.

$docker rmi {IMAGE name}

Upload Image to Docker Hub

commit

Commit is to save the Docker Container as a Docker Image.

$docker commit {Container name/ID} {New Docker Image name(:Tag name)}

push Push Docker Image to Docker Hub. In docker, the push destination is decided based on the image name, so usually the repository name = image name and version is managed by Tag name.

#Create the destination repository on Docker Hub first
$docker push {Repository name}

Only the new layer is pushed because it saves storage by having the same Image layer between images.

Change the Docker Image name

#To rename and save the image
$docker tag {Original image name:tag name} {New image name:tag name}

DockerFile

Build Docker File

#If the file name is DockerFile
$docker build {Directory path}
#Options when using a DockerFile other than the name DockerFile
#⚠ Basically, the name of DockerFile is generally DockerFile as it is.
$docker build {Directory path} -f option {file name}

DockerFile example

#FROM-based Docker Image
FROM ubuntu:latest
#RUN Imagelayer overlaid on top of running the above
RUN touch test
#COPY Image copy host data
COPY test.md /test_dir

reference

I learned a lot. Thank you very much! DockerDocumentation Docker Super Introductory Course How to delete Docker image and container

Recommended Posts

Neat, whose employment has been postponed to Corona, has started Docker, so I will leave a personal note.
Postgres environment construction with Docker I struggled a little, so note
I started to work at different times, so I made a bot that tells me the time to leave
I tried to make a calculator with Tkinter so I will write it
I was addicted to trying Cython with PyCharm, so make a note