Dockerfile
Dockerfile is a blueprint of docker image.
To build this, we can create new docker image.
Steps
- Prepare Dockerfile
- Build dockerfile
To build dockerfile, run following
docker build .
. is current directly and docker context
Layer
One line has one Layer.
But too much
Especially, we need to install a lot of packages to prepare environments we want to use.
In this case, we can use && commands to combine commands
Example
FROM ubuntu:latest
RUN apt-get update && apt-get install nginx \
apt-get install curl \
apt-get install essential-build
Dockerfile description
Description | Explanation | Example |
FROM | Original docker image | FROM ubuntu:latest |
USER | Use this user | USER vault |
ARG | Add arguments | ARG key=”value” |
ENTRYPOINT | Execute command(cannot override) | ENTRYPOINT [“java”, “-jar”, “/app.jar”] |
RUN | Execute command(can override) | RUN touch test |
CMD | Run command(not create layer) Describe at the bottom of Dockerfile CMD [“executable”, “param1”, “param2”] | CMD [“ls”] |
COPY | Copy folder, file COPY <src> <dst> | COPY test.txt /newdir/ |
ADD | Copy file (tar etc…) | ADD compress.tar / |
コメント