Development

Dockerfile, Docker의 컨테이너의 개념.

sonpro 2023. 3. 25. 18:10
반응형

Dockerfile

Concept of dockerfile, image, container in Docker

Docker is a popular containerization platform that allows developers to create, deploy, and run applications in a containerized environment. In this article, we will discuss the three key concepts of Docker: Dockerfile, image, and container.

Dockerfile

A Dockerfile is a text file that contains instructions for building a Docker image. It is a script that automates the process of creating a Docker image. The Dockerfile contains a set of instructions that tell Docker how to build the image. These instructions include the base image, the software packages to be installed, and the configuration settings.

Here is an example of a Dockerfile:

FROM ubuntu:18.04
RUN apt-get update && apt-get install -y apache2
COPY index.html /var/www/html/
EXPOSE 80
CMD ["apache2ctl", "-D", "FOREGROUND"]

In this example, we are using the Ubuntu 18.04 base image. We are installing the Apache web server and copying the index.html file to the /var/www/html/ directory. We are also exposing port 80 and starting the Apache web server.

Image

An image is a lightweight, standalone, and executable package that contains everything needed to run an application. It is a snapshot of a Docker container that includes the application code, runtime, system tools, libraries, and settings. An image is built from a Dockerfile using the docker build command.

Here is an example of how to build an image from a Dockerfile:

docker build -t myimage:1.0 .

In this example, we are building an image called myimage with the tag 1.0. The . at the end of the command specifies the build context, which is the directory where the Dockerfile is located.

Container

A container is a running instance of an image. It is a lightweight and isolated environment that runs the application. A container is created from an image using the docker run command.

Here is an example of how to run a container from an image:

docker run -d --name mycontainer -p 80:80 myimage:1.0

In this example, we are running a container called mycontainer from the myimage:1.0 image. We are also mapping port 80 of the container to port 80 of the host machine.

Conclusion

In conclusion, Docker is a powerful tool for containerization that allows developers to create, deploy, and run applications in a containerized environment. The three key concepts of Docker are Dockerfile, image, and container. A Dockerfile is a script that automates the process of creating a Docker image. An image is a lightweight, standalone, and executable package that contains everything needed to run an application. A container is a running instance of an image. By understanding these concepts, developers can leverage the power of Docker to build and deploy applications in a scalable and efficient manner.

반응형