It was created by myself as a docker beginner for docker beginners as well. I wrote this article by excerpting terms commonly used in Dockerfile and docker-compose. I hope it will be helpful to everyone. ✊
--Docker, docker-compose Beginners --For those who have forgotten how to write the file
Dockerfile is a text file that takes instructions and builds an image automatically. You can create the image as you like by writing her own Dockerfile without pulling.
FROM Specify Docker image (create it without permission even if there is no image locally)
FROM python:3.7
ENV Set environment variables (key, value)
ENV PYTHONUNBUFFERED 1
RUN Run the shell before creating the image
RUN mkdir /code
CMD Run the shell after creating the image, run only the last one even if you use more than one
CMD python3 app.py
WORKDIR Specifies the directory where the docker container starts commands
WORKDIR /usr/share/nginx/html
COPY Copy files from host to Docker image, not decompressed for compressed files
# /~/Absolute path if enclosed in, relative path of WORKDIR if not
COPY index.html index.html
ADD Copy files from host to Docker image, decompress for compressed files
# /~/Absolute path if enclosed in, relative path of WORKDIR if not
ADD requirements.txt /code/
VOLUME Specify the directory to mount the data on the host side
VOLUME /code
docker-compose is a tool for Docker applications that use YAML files to define and run multiple containers.
version: '3'
services:
db:
image: postgres
container_name: docker_compose_postgres
ports:
- "5555"
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
networks:
- docker_link
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
networks:
- docker_link
networks:
docker_link:
--version: version of docker-compose --service: Running application --image: Docker image specification --container_name: container name --ports: You can specify not only both host side and container side ports but also public port only. --environment: Add environment variables --build: Specify the directory where Dockerfile exists --command: Override the default command --volumes: Specify the directory to mount the host directory --depends_on: Specify dependencies between services --network: Specify which network to connect to --networks: Specifying networks
-Docker-compose overview -Compose File Reference
Recommended Posts