6. About Dockerfile
• This is a text file written docker
container composition
• We can create docker image
using this file instead of commit
command
7. Why use Dockerfile
• We have some problems by
commit command
– Manual operation to container
setup
– Write a document for composition
8. Why use Dockerfile
• We can reuse a cache created at
image creation
– When we build docker image using
dockerfile, docker commits and
caches the image of each step.
9. Docker command image (prior document)
Docker index
image
Container
Docker installed
OS
Ubuntu CentOS Debian
docker pull
docker push
docker rundocker
commit
image
Docker installed
OS
tar
archive
docker
export
docker import
- Basic Flow
- Advance Flow
12. Dockerfile fomat
• Format
– INSTRUCTION arguments
Not case-sensitive, however in the convention
• INSTRUCTION -> UPPERCASE
• Arguments -> lowercase
– The first instruction must be “FROM”
– Docker will treat lines that begin with # as a
comment
13. Dockerfile instruction
• FROM (must be the first)
– Usage: FROM <image> or FROM <image>:<tag>
Base image for subsequent instructions
• MAINTAINER
– Usage: MAINTAINER <name>
The Author field of the generated image
• RUN (has two formats)
– Usage: RUN <command> (this is executed by “/bin/sh -c”)
Execute a command in a new container
From https://docs.docker.com/reference/builder/
14. Dockerfile instruction
• CMD (has three formats)
– Usage: CMD command param1 param2
Provide defaults for an executing container
• EXPOSE
– Usage: EXPOSE <port> [<port>...]
listen on the specified network ports at runtime
• ADD
– Usage: ADD <src> <dest>
Copy files from <src> on host to <dest> on container
From https://docs.docker.com/reference/builder/
15. Dockerfile example
• The following is the dockerfile for openssh-
server
FROM centos:centos6
MAINTAINER cawamata
RUN yum update –y
RUN yum install –y openssh-server
RUN echo ‘root:test’ | chpasswd
RUN sed -i '/pam_loginuid¥.so/s/required/optional/' /etc/pam.d/sshd
RUN /sbin/service sshd start
EXPOSE 22
CMD /usr/sbin/sshd -D
17. Image creation from dockerfile
• SYNOPSIS
docker build [option] PATH | URL | -
– OPTION
• --force-rm=true|false
– Always remove intermediate containers, even after unsuccessful builds.
The default is false.
• --no-cache=true|false
– Do not use cache when building the image. The default is false.
• -q, --quiet=true|false
– Suppress the verbose output generated by the containers. The default is
false.
• --rm=true|false
– Remove intermediate containers after a successful build. The default is
true.
• -t, --tag="“
– Repository name (and optionally a tag) to be applied to the resulting
image in case of success
From https://github.com/docker/docker/blob/master/docs/man/docker-build.1.md
18. Demo for dockerfile
1.vim Dockerfile
2.docker build test Dockerfile
3.docker inspect test
4.docker run test