Docker Init lets you set up a Docker project in a snap. With just one CLI command, docker init
, you can generate everything you need.
Docker has revolutionised the software development process, simplifying software deployment and making it more accessible to other developers. The recently-introduced Docker Init command streamlines project creation by generating configuration files with a single command.
TL;DR
docker init
dockerises your application! :)
Docker Init 🐋
The command creates three files in your project:
- a Dockerfile
- a .dockerignore
- and a compose.yaml
In other words, all the files that are necessary for a complete Docker App.
To use the Docker Init command, you only need Docker Desktop > version 4.18. And of course a non-dockerised project, i.e. a project for which no Docker files exist yet.
Supported languages 👨💻
Currently, the command supports 5 programming languages:
- ASP.NET
- Go
- Node
- Python
- Rust
If a project does not involve any of the languages, the Dockerfile is configured to establish an entry point that is universally applicable.
However, it is highly likely that the capabilities of this command will be extended in future updates, leaving us intrigued.
Docker Init in Action 🎬
Let's get down to business and look at the command in action in a Node.js application.
> docker init
You will then be guided through a range of questions.
? What application platform does your project use? Node
? What version of Node do you want to use? (20.5.1)
? What application platform does your project use? Node
? What version of Node do you want to use? 20.5.1
? Which package manager do you want to use? [Use arrows to move, type to filter]
> npm - (detected)
yarn
pnpm
? What application platform does your project use? Node
? What version of Node do you want to use? 20.5.1
? Which package manager do you want to use? npm
? What command do you want to use to start the app? [tab for suggestions] (node index.js)
? What application platform does your project use? Node
? What version of Node do you want to use? 20.5.1
? Which package manager do you want to use? npm
? What command do you want to use to start the app? node index.js
? What port does your server listen on? 3000
And that is all. We get the three said files that we need for a complete Docker project.
To check the configuration, we run the docker compose
command: Running!
And the Dockerfile also works for a single Docker container. We get a running container for our application.
docker build -t docker-init-app .
docker run -p 3000:3000 docker-init-app
Advantages of Docker Init ⭐
In my eyes, the command offers numerous advantages for developers and teams:
- Accelerated project initialisation: Docker Init automates the creation of all configuration files. This eliminates the time-consuming manual creation of these files and speeds up development processes.
- Consistency and standardisation: Like CI/CD tools, using the Docker Init command ensures that all projects have a consistent and standardised Docker configuration. This leads to fewer configuration errors and improved team collaboration.
- Reduced error-proneness: Docker Init helps minimise errors in Docker configuration by implementing best practices and recommended structures for Docker projects. This leads to more robust and reliable applications.
Overall, Docker Init makes it easier for developers to enter the world of Docker projects and helps to increase the efficiency, reliability and consistency of applications. This leads to accelerated development and an overall improved development quality.
Psssst! Do you know the difference between (Docker) containers and virtual machines (VMs)?
Conclusion 📖
The Docker Init command highlights Docker’s prominence in software development. By using this command, developers can rapidly create Docker projects while minimising configuration file setup.