docker init
docker init
프로젝트를 컨테이너에서 실행하는 데 필요한 시작 파일(Dockerfile, compose.yaml 등)을 만들어주는 명령이에요. Docker Desktop이 제공하는 CLI로, 프로젝트에 맞는 적절한 기본값으로 파일들을 자동 생성해줘요.
출처: 문서
본문
docker init은 프로젝트를 컨테이너에서 실행하는 데 필요한 파일로 초기화하는 명령이에요.
Docker Desktop은 docker init CLI 명령을 제공해요. 프로젝트 디렉터리에서 docker init을 실행하면 프로젝트에 적합한 기본값으로 다음 파일들을 만드는 과정을 안내해줘요.
- .dockerignore
- Dockerfile
- compose.yaml
- README.Docker.md
파일이 이미 존재하면 프롬프트가 나타나 경고를 표시하고 모든 파일을 덮어쓸 옵션을 줘요. docker-compose.yaml이 compose.yaml 대신 이미 존재하면 docker init은 docker-compose.yaml을 Compose 파일 이름으로 사용해 덮어쓸 수 있어요.
Warning
덮어쓴 파일은 복구할 수 없어요. 덮어쓰기를 선택하기 전에 기존 파일을 백업하려면 파일 이름을 바꾸거나 다른 디렉터리로 복사하세요.
docker init을 실행한 뒤 다음 템플릿 중 하나를 고를 수 있어요.
- ASP.NET Core: ASP.NET Core 애플리케이션에 적합.
- Go: Go 서버 애플리케이션에 적합.
- Java: Maven을 사용하고 uber jar로 패키징하는 Java 애플리케이션에 적합.
- Node: Node 서버 애플리케이션에 적합.
- PHP with Apache: PHP 웹 애플리케이션에 적합.
- Python: Python 서버 애플리케이션에 적합.
- Rust: Rust 서버 애플리케이션에 적합.
- Other: 애플리케이션을 컨테이너화하는 일반 목적의 시작점.
docker init이 끝나면 생성된 파일을 수정해 프로젝트에 맞출 필요가 있을 수 있어요. 파일에 대한 자세한 내용은 다음 주제를 참고해요.
docker init [OPTIONS]
지원하는 옵션은 다음과 같아요.
| 옵션 | 기본값 | 설명 |
|---|---|---|
--version |
init 플러그인의 버전 표시 |
docker init 실행 예제
다음 예제는 docker init을 실행한 뒤의 초기 메뉴를 보여줘요. 언어·프레임워크별 옵션을 보려면 추가 예제를 참고해요.
$ docker init
Welcome to the Docker Init CLI!
This utility will walk you through creating the following files with sensible defaults for your project:
- .dockerignore
- Dockerfile
- compose.yaml
- README.Docker.md
Let's get started!
? What application platform does your project use? [Use arrows to move, type to filter]
> PHP with Apache - (detected) suitable for a PHP web application
Go - suitable for a Go server application
Java - suitable for a Java application that uses Maven and packages as an uber jar
Python - suitable for a Python server application
Node - suitable for a Node server application
Rust - suitable for a Rust server application
ASP.NET Core - suitable for an ASP.NET Core application
Other - general purpose starting point for containerizing your application
Don't see something you need? Let us know!
Quit
Go 선택 예제
Go를 선택했을 때 나타나는 프롬프트와 예시 입력이에요.
? What application platform does your project use? Go
? What version of Go do you want to use? 1.20
? What's the relative directory (with a leading .) of your main package? .
? What port does your server listen on? 3333
CREATED: .dockerignore
CREATED: Dockerfile
CREATED: compose.yaml
CREATED: README.Docker.md
✔ Your Docker files are ready!
Take a moment to review them and tailor them to your application.
When you're ready, start your application by running: docker compose up --build
Your application will be available at http://localhost:3333
Consult README.Docker.md for more information about using the generated files.
Node 선택 예제
Node를 선택했을 때 나타나는 프롬프트와 예시 입력이에요.
? What application platform does your project use? Node
? What version of Node do you want to use? 18
? Which package manager do you want to use? yarn
? Do you want to run "yarn run build" before starting your server? Yes
? What directory is your build output to? (comma-separate if multiple) output
? What command do you want to use to start the app? node index.js
? What port does your server listen on? 8000
CREATED: .dockerignore
CREATED: Dockerfile
CREATED: compose.yaml
CREATED: README.Docker.md
✔ Your Docker files are ready!
Take a moment to review them and tailor them to your application.
When you're ready, start your application by running: docker compose up --build
Your application will be available at http://localhost:8000
Consult README.Docker.md for more information about using the generated files.
Python 선택 예제
Python을 선택했을 때 나타나는 프롬프트와 예시 입력이에요.
? What application platform does your project use? Python
? What version of Python do you want to use? 3.8
? What port do you want your app to listen on? 8000
? What is the command to run your app (e.g., gunicorn 'myapp.example:app' --bind=0.0.0.0:8000)? python ./app.py
CREATED: .dockerignore
CREATED: Dockerfile
CREATED: compose.yaml
CREATED: README.Docker.md
✔ Your Docker files are ready!
Take a moment to review them and tailor them to your application.
When you're ready, start your application by running: docker compose up --build
Your application will be available at http://localhost:8000
Consult README.Docker.md for more information about using the generated files.
Rust 선택 예제
Rust를 선택했을 때 나타나는 프롬프트와 예시 입력이에요.
? What application platform does your project use? Rust
? What version of Rust do you want to use? 1.70.0
? What port does your server listen on? 8000
CREATED: .dockerignore
CREATED: Dockerfile
CREATED: compose.yaml
CREATED: README.Docker.md
✔ Your Docker files are ready!
Take a moment to review them and tailor them to your application.
When you're ready, start your application by running: docker compose up --build
Your application will be available at http://localhost:8000
Consult README.Docker.md for more information about using the generated files.
ASP.NET Core 선택 예제
ASP.NET Core를 선택했을 때 나타나는 프롬프트와 예시 입력이에요.
? What application platform does your project use? ASP.NET Core
? What's the name of your solution's main project? myapp
? What version of .NET do you want to use? 6.0
? What local port do you want to use to access your server? 8000
CREATED: .dockerignore
CREATED: Dockerfile
CREATED: compose.yaml
CREATED: README.Docker.md
✔ Your Docker files are ready!
Take a moment to review them and tailor them to your application.
When you're ready, start your application by running: docker compose up --build
Your application will be available at http://localhost:8000
Consult README.Docker.md for more information about using the generated files.
PHP with Apache 선택 예제
PHP with Apache를 선택했을 때 나타나는 프롬프트와 예시 입력이에요. PHP with Apache 템플릿은 순수 PHP 애플리케이션과 Composer를 의존성 관리자로 사용하는 애플리케이션 모두에 적합해요. docker init을 실행한 뒤 애플리케이션에 필요한 PHP 확장을 Dockerfile에 직접 추가해야 해요.
? What application platform does your project use? PHP with Apache
? What version of PHP do you want to use? 8.2
? What's the relative directory (with a leading .) for your app? ./src
? What local port do you want to use to access your server? 9000
CREATED: .dockerignore
CREATED: Dockerfile
CREATED: compose.yaml
CREATED: README.Docker.md
✔ Your Docker files are ready!
Take a moment to review them and tailor them to your application.
If your application requires specific PHP extensions, you can follow the instructions in the Dockerfile to add them.
When you're ready, start your application by running: docker compose up --build
Your application will be available at http://localhost:9000
Consult README.Docker.md for more information about using the generated files.
Java 선택 예제
Java를 선택했을 때 나타나는 프롬프트와 예시 입력이에요.
? What application platform does your project use? Java
? What version of Java do you want to use? 17
? What's the relative directory (with a leading .) for your app? ./src
? What port does your server listen on? 9000
CREATED: .dockerignore
CREATED: Dockerfile
CREATED: compose.yaml
CREATED: README.Docker.md
✔ Your Docker files are ready!
Take a moment to review them and tailor them to your application.
When you're ready, start your application by running: docker compose up --build
Your application will be available at http://localhost:9000
Consult README.Docker.md for more information about using the generated files.
Other 선택 예제
Other를 선택했을 때의 출력이에요.
? What application platform does your project use? Other
CREATED: .dockerignore
CREATED: Dockerfile
CREATED: compose.yaml
CREATED: README.Docker.md
✔ Your Docker files are ready!
Take a moment to review them and tailor them to your application.
When you're ready, start your application by running: docker compose up --build
Consult README.Docker.md for more information about using the generated files.