Docker images are further categorized in 2 types
- Base Image
If we need to have more control on whats going in my images we should use base image, which means we need to create a Docker image from scratch.
- Parent Image
Parent image is something we will be using image created by someone else and build our image on top of this image.
We can write Docker instructions in a file name Dockerfile. Lets see some Dockerfile instructions.
- FROM
This must be the fist line in Dockerfile.
- MAINTAINER
This is to add the Maintainer in Docker image.
- ARG
Build time variables and only available during the creation of Docker image.
- ENV
To setup the environment variable in Docker container.
- COPY
It takes source and destination locations to copy the file from host machine where we will be building the docker image to docker image.
- ADD
It do what COPY does but apart from that it also support the URL’s to get download from external sources. Also it understand the tar formats.
- RUN
TO execute command in docker image layer.
- CMD
sets default command and/or parameters, which can be overwritten from command line when docker container runs.
- ENTRYPOINT
configures a container that will run as an executable.
- EXPOSE
To expose the ports on which the application inside the container listening on.
- WORKDIR
Its sets up the working directory inside the container.
- LABEL
Its a metadata for the container it takes Key Value pair.
- VOLUME
It creates a mount point inside the Docker container from the host machine.
sudo debootstrap stretch stretch > /dev/null sudo tar -C stretch -c . | docker import - stretch
- To create a Docker we need to create a Dockerfile, below is basic docker file.
FROM scratch ADD hello.sh /hello.sh
- To create a docker image use below command
docker build -t myfirstdockerimage . or you can specify the Dockerfile path too docker build -t myfirstdockerimage . -f Dockerfile
- To run a docker container for the image created with above step
docker run myfirstdockerimage
- To check the docker images
docker images
- To check the running dockers
docker container ls or docker ps
- To stop the docker container
docker stop <containerid>
- To stop the docker container