Understand in 5 minutes !! How to use Docker

Understand in 5 minutes !! How to use Docker

I will explain Docker in 5 minutes !! If you read this, you can also reproduce the environment of the dissertation !! Read the documentation for more details !!

How to use Docker is as follows !!

  1. Write a Dockerfile !! </ strong>
  2. Based on the Dockerfile, execute the build command to create an image !! </ strong>
  3. run !! </ strong>

Only 3 steps !!

I'll write it again !!

  1. Write a Dockerfile !! </ strong>
  2. Based on the Dockerfile, execute the build command to create an image !! </ strong>
  3. run !! </ strong>

An image in docker is like a program !! And the state where it is moving is called container </ strong> !!

This is similar to the relationship between programs and processes !! Another analogy is similar to the relationship between a class and an instance !!

Well then, let's get into the explanation of each step !!

1. Write a Dockerfile !!

In the Dockerfile, write the information you want to burn into the image !! In other words, write the one you want to have when the container moves !!

An example is shown below !!!

FROM ubuntu:18.04

RUN apt-get update && apt-get install -y vim

Each line in the Dockerfile Command blank arguments </ strong> Consists of !!

Here are some frequently used commands !! Only two !!

FROM </ strong> and RUN </ strong> If you just remember it, you can do something !! First of all, it is important to get used to it !!

FROM </ strong> specifies the original image !! Writing this makes it easier to create images !! For example, if you want a tensorflow environment, images for it are distributed !! If you don't understand, think of it as class inheritance !!

RUN </ strong> is a command to execute Linux commands !! Execute the Linux command with the RUN blank Linux command !!

Do what you want to do with the image by RUN !!

For example, if you want vim to be available when you launch your virtual environment,

RUN apt-get install -y vim

Just write in the Dockerfile !!

Next, let's get into the image creation method !!

2. Based on the Dockerfile, execute the build command to create an image !! Once the Dockerfile is complete, all you have to do is create an image with the build command !!
docker build -t image name path to Dockerfile

The image is completed with just this !!

What's wrong?

3. run !!

Once the class is complete, I want to create an instance, Once the program is complete, I want to run it as a process !!

In the same way, once the image is complete, you'll want to launch a container !!

docker run -it --rm image name

Now it will be fine and the container will move in the current terminal !!

At the end

Even if you don't know docker If you have 3 steps in mind, you can do something!

Recommended Posts