Create a Dockerfile
Create a new file calledDockerfile
and add the following items.
busybox
image like we used before. It then adds a custom entrypoint.sh
script, makes it executable, and configures it as the entrypoint.
The entrypoint script
Now let’s createentrypoint.sh
with the following contents:
While we named this script
entrypoint.sh
you will see a variety of naming conventions; such as:start.sh
CMD.sh
entry_path.sh
script
but it is dependent on the maintainers of that repository.Why an entrypoint script:
- It lets you customize what command gets run when a container starts from your image.
- For example, our script runs date to print the time.
- Without it, containers would exit immediately after starting.
- Entrypoints make images executable and easier to reuse.
Build the image
With those files created, we can now build a Docker image using our Dockerfile:my-time-image
from the Dockerfile in the current directory.
Why build a custom image:
- Lets you package up custom dependencies and configurations.
- For example you can install extra software needed for your app.
- Makes deploying applications more reliable and portable.
- Instead of installing things manually on every server, just use your image.
- Custom images can be shared and reused easily across environments.
- Building images puts your application into a standardized unit that “runs anywhere”.
- You can version images over time as you update configurations.