What is Dockerfile, Docker Image and container ?
When I started reading about Docker, I was confused about the relationship between Docker file vs docker image vs docker container !
Short answer to my question is:
- Docker file is where I need to script my steps on what actions to be done before I make a docker image.
- A sample docker file as below:
- here below in the code, I am pulling JDK environment in line 1.
- copying a java class to app directory in line 2,
- setting app as working directory in line 3 for my docker container after i convert image to container.
- Then finally running my app in line 4.
FROM java:8-jdk-alpine
COPY HelloWorld.class /app/
WORKDIR /app
ENTRYPOINT [“java”,”HelloWorld”] - Docker image is created using the above docker file by building it. (command : docker build -t myhelloworldapp . )
- then spin up the container by using command : docker run myhelloworldapp
Docker Basics
Docker build command is used to generate docker images out of dockerfile line by line instructions.
Docker build is managed by docker daemon and not by CLI.
Docker build context can be a set of files in a specified directory or a git repository.
PATH is for directory and URL is for git
dockerignore file is used to ignore not required files.
Docker daemon runs each instructions from Dockerfile and commits each instructions to new Image.
Docker has build cache to speed up build process.