First post on the Advent Calendar! This article is Day 24 of the Phone Appli Advent Calendar. Thank you!
――It was "Docker" that was frustrating several times ... ――Because I couldn't understand terms such as "image" and "container" ... ――I often see it in books and sites ...
In short, it's a "memorial" article to reduce frustration with docker during work or other studies. Yes····
Let's try it now ~~~~
tool | Explanation |
---|---|
docker | Installation complete |
VScode | Because there are plug-ins |
--A platform that allows you to create and execute container-type virtual environments
--It is one of the virtual environments. (Using a technology called "namespace" implemented in the Linux kernel) --On the host OS (on your PC's OS), you can create a virtual environment called a container and operate the libraries required for application development as one. --Multiple applications can be run on one host OS (hence, it is said to have a high affinity with microservices).
--In the container, you can start "vim" with the specified file (/sample/test.md).
I don't have a strong commitment to vim, but by doing something in the container, You can see the difference from the host (your PC) ...
FROM ubuntu:latest
RUN apt-get update && apt-get install -y \
vim
RUN mkdir sample
WORKDIR /sample
RUN touch test.md
WORKDIR /
CMD ["ls"]
You can do this to go to the specified directory inside the container and start vim
FROM ubuntu:latest
FROM
basically specifies the OS (this time, ubuntu, which is said to be friendly to beginners derived from Linux) is specified.
--I don't want to make it too big as it is the basis of docker image
RUN apt-get update && apt-get install -y \
vim
RUN mkdir sample
WORKDIR /sample
RUN touch test.md
WORKDIR /
RUN
is ** execution command **
--Run update
and install
with the apt-get
command for ubuntu
WORKDIR
is ** directory move **
――You have moved twice ... (There must be a better way ...)
CMD ["ls"]
CMD
is the first command to be executed when the container is started. Used when you want to specify the port number
--This time, execute the ls
command to display a list of directories.
docker build -t "The name of the image you want to give" . //->Image is created
docker images //-> "sample"Image is created
docker run image name//->Create and start a container, and the ls command is executed inside the container. The container will be closed soon, but ...
docker ps -a //-> `COMMAND`In the column`ls`There should be a history of commanding ...
By the way, dockerfile creation-> image creation-> container creation / start-> I executed the command in the container,
--I can't stop in the container and hit the command myself ** (I can't reach the goal) **
-it
and bash
to the optionsdocker run -it image name bash//-> 「-It is possible to hit the command on ubuntuOS in the container with "it image name bash"
-it
can be separated by -i
and -t
(you can execute it with either one, but standard input is not possible or the display is not clean).
bash
is a shell command that launches inside a container
After that, hit the following commands in order to reach the goal **
cd sample
vim test.md
Originally, Docker is often used for web development environment construction and data analysis infrastructure such as python and kotlin. So, you may not be able to create an image to use with this implementation alone: fearful :, It may be less frustrating to see "in a container ..." or "create an image ..." that appears in reference books and sites. I hope this article will increase the number of engineers who are less frustrated with docker.
See you soon····
Recommended Posts