🐋 Docker Init command: Create Docker projects automatically 🚀
Tags: docker, devops, productivity
Published: 2023-10-04 12:00:00

__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.

➡️ [Download Docker Desktop](https://www.docker.com/products/docker-desktop/)


## 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](https://webdeasy.de/en/node-js-tutorial-en/) application.
```
> docker init
```
![Docker Init command in a Node project in Visual Studio Code](https://webdeasy.de/wp-content/uploads/2023/09/docker-init-before-execution.jpg)
![Executed Docker Init command](https://webdeasy.de/wp-content/uploads/2023/09/docker-init-start.jpg)

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.

![Result of the Docker Init command](https://webdeasy.de/wp-content/uploads/2023/09/docker-init-after-execution.jpg)

![Dockerfile, .dockerignore and compose.yaml](https://webdeasy.de/wp-content/uploads/2023/09/docker-init-files.jpg)

To check the configuration, we run the `docker compose` command: Running!
![docker compose up
](https://webdeasy.de/wp-content/uploads/2023/09/docker-compose-running.jpg)

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](https://webdeasy.de/en/what-is-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)](https://webdeasy.de/en/docker-vs-virtual-machines/)?


## 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.