Containerize your application
When working with containers, you typically need to create a Dockerfile
to define your image and a compose.yaml
file to define how to run it.
To help you create these files, Docker Desktop has the docker init
command. Run this command in a terminal within your project folder. docker init
creates all the required files to containerize your application. This walkthrough shows you how this works.
Before you start, get Docker Desktop.
Step 1: Run the command to create Docker assets
Choose one of your own applications that you would like to containerize, and in a terminal, run the following commands. Replace /path/to/your/project/
with the directory containing your project.
Tip
To run Docker commands, you must use a terminal. Based on your operating system, you can open a terminal by doing the following:
For Windows, select the Start Menu, specify
cmd
, and then select Command Prompt.For Mac, select the Launchpad icon in the Dock, specify
Terminal
in the search field, then select Terminal.
$ cd /path/to/your/project/
$ docker init
Step 2: Follow the on-screen prompts
docker init
walks you through a few questions to configure your project with sensible defaults. Specify your answers and press Enter
.
Step 3: Try to run your application
Once you have answered all the questions, run the following commands in a terminal to run your project. Replace /path/to/your/project/
with the directory containing your project.
$ cd /path/to/your/project/
$ docker compose up
Step 4: Update the Docker assets
The docker init
command tries its best to do the heavy lifting for you, but sometimes there's some assembly required. In this case, you can refer to the
Dockerfile reference and
Compose file reference to learn how to update the files created by docker init
.
Summary
In this walkthrough, you learned how to containerize your own application.
Related information:
- Read more about docker init
- Learn more about Docker assets in the Dockerfile reference and Compose file reference
Next steps
Continue to the next walkthrough to learn how to publish an application as an image on Docker Hub.