Dockerfile:
Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text file that contains instructions for building a Docker image. It tells Docker what base image to use, what commands to run, and what files to include. For example, if you were making a container for a website, the Dockerfile might tell Docker to use an official web server image, copy the files for your website into the container, and start the web server when the container starts.
Dockerfile instructions:
FROM
Create a new build stage from a base image.
RUN
Execute build commands.
WORKDIR
Change working directory.
VOLUME
Create volume mounts.
COPY
Copy files and directories.
ADD
Add local or remote files and directories.
ARG
Use build-time variables.
ENTRYPOINT
Specify default executable.
CMD
Specify default commands.
ENV
Set environment variables.
EXPOSE
Describe which ports your application is listening on.
HEALTHCHECK
Check a container's health on startup.
LABEL
Add metadata to an image.
MAINTAINER
Specify the author of an image.
ONBUILD
Specify instructions for when the image is used in a build.
SHELL
Set the default shell of an image.
STOPSIGNAL
Specify the system call signal for exiting a container.
USER
Set user and group ID.
Let's learn how to write a Dockerfile and build image.
Dockerfile to to create a python app.
Build docker image -- docker build -t python-app .
Run container from above image -- docker run -d -p 5000:5000 --name python-app python-app
Check if the app is running fine -- public_ip/5000
Now push image to Docker Hub(Public repository)
Docker login on docker host
Now, we need to tag the image we want push to docker hub
Now, push the image to docker hub and verify in docker hub