In the previous step, you ran a command that prints the container’s uptime. Now you’ll create a Dockerfile to customize the contents of your own Docker image.
Create a new file called Dockerfile
and add the following items.
This Dockerfile starts from the busybox
image like we used before. It then adds a custom entrypoint.sh
script, makes it executable, and configures it as the entrypoint.
Now let’s create entrypoint.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
These files are normally placed in a folder called script
but it is dependent on the maintainers of that repository.
This is a simple script that will print the current time when the container starts.
With those files created, we can now build a Docker image using our Dockerfile:
This will build the image named my-time-image
from the Dockerfile in the current directory.
Finally, let’s run a container from our new image:
We should see the same output as before printing the current time!
Entrypoints and Dockerfiles let you define reusable, executable containers that run the software and commands you need. This makes deploying and sharing applications much easier without per-server configuration.
By putting commands like this into a Dockerfile, you can easily build reusable and shareable images.