์ฌ๊ธฐ์ ์ ์ฒด ์์ ์ ์ฅ์๊ฐ ์์ต๋๋ค.
https://github.com/devinrsmith/docker-compose-build-test
docker-compose build
์๋ชป ์ฌ์ฉํ๊ณ ์๋ค๋ฉด ์๋ ค์ฃผ์ธ์!
ํ์ผ ํ์์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
.dockerignore
subdir/
์ subdir
ํฉ๋๋ค.
.dockerignore๊ฐ docker build -t subdir ../
์์๋ ์๋ํ์ง๋ง docker-compose build
์์๋ ์๋ํ์ง ์๋ ์ด์ ๋ ๋ฌด์์
๋๊น?
docker-compose 1.2.0์ ์คํํ๋ ๊ฒ๊ณผ ๋์ผํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
๋ฐ๋๋ผ ๋์ปค ๋น๋๋ฅผ ์คํํ๋ฉด ๋ฌด์ ํ์ผ์ ๊ฐ์ ธ์ ๊ฑฐ๊ธฐ์ ์ด๋ฏธ์ง np๋ฅผ ๋น๋ํฉ๋๋ค.
๊ทธ๋ฌ๋ docker-compose๋ ํํ ์ฌ๋์๊ฐ ์๋ ์๋ ๋ฌด์ ํ์ผ์ ์ฌ์ฉํ์ง ์์ต๋๋ค.
docker-py ๋ฌธ์ ์ฒ๋ผ ๋ณด์ ๋๋ค. https://github.com/docker/docker-py/pull/604 ์์ ์์ ์์ ์ด ์งํ ์ค
@aanand ๋ https://github.com/docker/docker-py/pull/604๊ฐ ์ค๋จ๋์ด ์ด์ ํ์์ ์ ๊ฑฐ ๋ ๊ฒ์ฒ๋ผ ๋ณด์ ๋๋ค.
@thaJeztah ์์ ์ ๊ณ์ํ๊ธฐ ์ํด https://github.com/docker/docker-py/pull/721 ์ ๋ง๋ค์์ต๋๋ค.
์๋ ํ์ธ์,
.dockerignore์ ์ด์ํ ๋ฌธ์ ๊ฐ ํ๋ ์์ต๋๋ค.
*.sh
!awesome/script.sh
docker ๋น๋๋ก ๋ชจ๋ ๊ด์ฐฎ์ง ๋ง docker-compose๋ "awesome / script.sh"๋ฅผ ๋ณด์ง ๋ชปํ์ต๋๋ค.
๋๋ ๊ฐ์ ๋ฌธ์ ์ ์์ต๋๊น?
https://github.com/docker/docker-py/pull/721์ ์ํด ์์ ๋ ์๋ ค์ง ๋ฒ๊ทธ ์ธ @twillouer -1.5.0์ Compose ์ธก์์ ์์ ๋ฉ๋๋ค.
๊ฐ์ฌ !
์ผ๋ถ ์ปดํจํฐ์ ์ต์ git master์์๋ ์ฌ์ ํ ์์๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ด ๊ตฌ์ฑ์ด ์ฃผ์ด์ง ์ปดํจํฐ์์๋ ์๋ํ์ง ์์ต๋๋ค.
์ปค๋ 3.16.0 (lxc-docker ๋ฒ์ 1.7.1, ๋น๋ 786b29d)์ด์๋ Debian 8.2
docker-compose๋ git master์ด๊ณ HEAD๋ dabf1e8657674014a5bc89f99edbf2fe0629bb71์
๋๋ค.
.dockerignore๋ docker ๋น๋ (์ฆ์ ์คํ ๋จ)์์๋ ์ ์๋ํ์ง๋ง docker-compose (์ฌ๋ฌ ๋ถ ๋์ ์ ๋ก๋ํด์๋ ์๋๋ ํญ๋ชฉ์ ์ ๋ก๋)์์๋ ์๋ํ์ง ์์ต๋๋ค.
# 2100 ์ฐธ์กฐ
๋๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. docker-compose๋ ".dockerignore"๋ฅผ ๋ฌด์ํฉ๋๋ค. "๋์ปค ๋น๋"๊ฐ ์ ์๋ํฉ๋๋ค.
์์คํ
: Windows 10
์ด์ ์ถ์ ๋ Docker Toolbox๋ฅผ ์ฌ์ฉํ์ฌ ๋์ผํ ๋ฌธ์ ๊ฐ ๋ฐ์ํฉ๋๋ค.
.dockerignore
์ฌ์ ํ ๋ฌธ์ ๊ฐ์๋ ๊ฒ ๊ฐ์ต๋๋ค. compose 1.5.0์์ ์ด๋ฌํ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ ๊ฒฝ์ฐ ์ค๋ฅ๋ฅผ ์ฌํ ํ ์ ์๋๋ก ์ํ .dockerignore
๋ฐ ๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ๋ฅผ ํฌํจ ํด์ฃผ์ธ์.
๋ ์์ ์ฌ์ฉ ์ฌ๋ก๋ฅผ ์ ๊ณตํ์ง ์์์ ์ฃ์กํ์ง๋ง ๋ค์๊ณผ ๊ฐ์ด ๋ฌธ์ ๋ฅผ ๋ฐ๊ฒฌํ์ต๋๋ค.
๋ด ํ๋ก์ ํธ์ package.json
์ด ์์ต๋๋ค.
{
"dependencies": {
"grunt-contrib-uglify": "^0.9.2"
}
}
๊ฒ๋ค๊ฐ์ด docker-compose.yml
:
web:
build: .
Dockerfile
์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
FROM node:0.12
๋ด .dockerignore
์๋ ํ ์ค์ด ํฌํจ๋์ด ์์ต๋๋ค (ํํ ์ฌ๋์๋ฅผ ์ถ๊ฐํ๋ ค๊ณ ์๋ํ์ง๋ง ๋ฌธ์ ๊ฐ ์ง์๋จ).
์ด์ ํ ์ ์์ต๋๋ค
> npm install
(...snip...)
> docker build .
Sending build context to Docker daemon 5.12 kB
ํ๋ฅญํฉ๋๋ค. 5KiB ๋ง ์ ์ก๋ฉ๋๋ค ( node_modules
๋ ์ด 10MiB). docker-compose
์์ Q:\sites\test
:
> npm install
(...snip...)
> docker-compose up
Building web
Traceback (most recent call last):
File "D:\opt\python\Scripts\docker-compose-script.py", line 9, in <module>
load_entry_point('docker-compose==1.5.0dev', 'console_scripts', 'docker-compose')()
File "D:\opt\python\lib\site-packages\compose\cli\main.py", line 54, in main
command.sys_dispatch()
File "D:\opt\python\lib\site-packages\compose\cli\docopt_command.py", line 23, in sys_dispatch
self.dispatch(sys.argv[1:], None)
File "D:\opt\python\lib\site-packages\compose\cli\docopt_command.py", line 26, in dispatch
self.perform_command(*self.parse(argv, global_options))
File "D:\opt\python\lib\site-packages\compose\cli\main.py", line 170, in perform_command
handler(project, command_options)
File "D:\opt\python\lib\site-packages\compose\cli\main.py", line 583, in up
detached=detached
File "D:\opt\python\lib\site-packages\compose\project.py", line 313, in up
detached=detached
File "D:\opt\python\lib\site-packages\compose\service.py", line 404, in execute_convergence_plan
container = self.create_container(do_build=do_build)
File "D:\opt\python\lib\site-packages\compose\service.py", line 303, in create_container
self.ensure_image_exists(do_build=do_build)
File "D:\opt\python\lib\site-packages\compose\service.py", line 326, in ensure_image_exists
self.build()
File "D:\opt\python\lib\site-packages\compose\service.py", line 718, in build
dockerfile=self.options.get('dockerfile', None),
File "D:\opt\python\lib\site-packages\docker\api\build.py", line 48, in build
context = utils.tar(path, exclude=exclude, dockerfile=dockerfile)
File "D:\opt\python\lib\site-packages\docker\utils\utils.py", line 85, in tar
t.add(os.path.join(root, path), arcname=path, recursive=False)
File "D:\opt\python\lib\tarfile.py", line 1998, in add
tarinfo = self.gettarinfo(name, arcname)
File "D:\opt\python\lib\tarfile.py", line 1870, in gettarinfo
statres = os.lstat(name)
WindowsError: [Error 3] Das System kann den angegebenen Pfad nicht finden: 'Q:\\sites\\test\\node_modules\\grunt-contrib-uglify\\node_modules\\maxmin\\node_modules\\pretty-bytes\\node_modules\\meow\\node_modules\\normalize-package-data\\node_modules\\validate-npm-package-license\\node_modules\\spdx-correct\\node_modules\\spdx-license-ids\\spdx-license-ids.json'
(์ด ์ปดํจํฐ์์ 1.5.0dev๋ฅผ ์ฌ์ฉํ๊ณ ์์ง๋ง ์ต์ข 1.5.0์ผ๋ก ๋ค๋ฅธ ์ปดํจํฐ์์ ๋๊ฐ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค).
๋
ธ๋๋ฅผ ์ฌ์ฉํ๋ฉด Windows์์ ๋๋ฌด ๊ธด ๊ฒฝ๋ก ๋ฐ ํญ๋ชฉ์ ๋ํ ๋ฌธ์ ๊ฐ ์์ฃผ ๋ฐ์ํ์ง๋ง Docker-Compose๊ฐ node_modules๋ฅผ tar๋ฅผ ์๋ํ๋ค๋ ์ฌ์ค์ .dockerignore
๊ฐ ๋ฌด์๋๋ค๋ ํ์์
๋๋ค.
FWIW, Docker-compose 1.5.0dev๋ฅผ ์ฌ์ฉํ๋ Linux (Ubuntu)์์ ์ฌ์ ํ ๋ฌธ์ ๊ฐ ์์ผ๋ฏ๋ก Windows์ ๊ฒฉ๋ฆฌ๋์ง ์์์ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ ํ๋ก๋์ ๋จธ์ ์ ์์ผ๋ฏ๋ก ์ต์ํ์ ํ ์คํธ ์ผ์ด์ค๋ฅผ ์ฝ๊ฒ ๊ตฌ์ฑ ํ ์ ์์ต๋๋ค (ํ ์คํธ ๋จธ์ ์์๋ ์ ์๋ํฉ๋๋ค).
๋๋ ๋ํ์ด ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ :
docker-compose.yml
web
+ .dockerignore
+ Dockerfile
+ node_modules
+ ...
docker-compose.yaml
web:
build: web
tty: true
ports:
- 8081:5000
Dockerfile
FROM microsoft/aspnet
# Curl, node, npm, bower, grunt
RUN apt-get update && apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup | bash -
RUN apt-get install -y nodejs
RUN npm install -g bower
RUN npm install -g grunt-bower-cli
RUN npm install -g grunt
RUN npm install -g grunt-cli
RUN npm install -g grunt-bower-task
# Copy the project.json file first, then do a restore.
# This ensures that as long as project.json doesn't change, it will avoid
# doing a package restore
COPY project.json /app/
COPY bower.json /app/
COPY gruntfile.js /app/
COPY package.json /app/
WORKDIR /app
RUN ["dnu", "restore"]
# Then copy the rest of the files
COPY . /app
# Expose the port that the website listens on
EXPOSE 5000
# And start the website
ENTRYPOINT ["dnx", "-p", "project.json", "web"]
.dockerignore
๊ฒฐ๊ณผ:
Pi<strong i="19">@Ricci</strong> MINGW64 /d/proj/Repro
$ docker-compose build
Building web
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "C:\projects\compose\compose\cli\main.py", line 54, in main
File "C:\projects\compose\compose\cli\docopt_command.py", line 23, in sys_dispatch
File "C:\projects\compose\compose\cli\docopt_command.py", line 26, in dispatch
File "C:\projects\compose\compose\cli\main.py", line 171, in perform_command
File "C:\projects\compose\compose\cli\main.py", line 192, in build
File "C:\projects\compose\compose\project.py", line 235, in build
File "C:\projects\compose\compose\service.py", line 683, in build
File "c:\projects\compose\venv\lib\site-packages\docker\api\build.py", line 48, in build
File "c:\projects\compose\venv\lib\site-packages\docker\utils\utils.py", line 85, in tar
File "c:\python27-x64\Lib\tarfile.py", line 2000, in add
File "c:\python27-x64\Lib\tarfile.py", line 1872, in gettarinfo
WindowsError: [Error 3] The system cannot find the path specified: 'D:\\proj\\Repro\\web\\node_modules\\babel-preset-react\\node_modules\\babel-plugin-transform-react-jsx\\node_modules\\babel-helper-builder-react-jsx\\node_modules\\babel-types\\node_modules\\babel-traverse\\node_modules\\babel-code-frame\\node_modules\\js-tokens\\changelog.md'
docker-compose returned -1
+1
์๋ฌด๋ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ฐพ์์ต๋๊น? ๋๋ Dockerfile์์๋ง ๋ชจ๋ ๊ฒ์ ์๋ํ๊ณ ์์ง๋ง ์์ง ์ด์ด ์์์ต๋๋ค.
์ด ๋ฌธ์ ๋ ๋ฐ์ํฉ๋๋ค. ๋ชจ๋ ์ฌ๋์ด ์คํ์ค์ธ ๋ ธ๋ ๋ฒ์ ๊ณผ ๊ด๋ จ์ด์์ ์ ์์ต๋๊น? ์ด ๋ฌธ์ ๋ฅผ ํตํด : https://github.com/npm/npm/issues/3697 .. ๋ ธ๋ ์ ๊ทธ๋ ์ด๋ (๋ณด๋ค ๊ตฌ์ฒด์ ์ผ๋ก npm 3+๋ก)๊ฐ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์๋ค๊ณ ์๊ฐํ์ง๋ง ํต ์ต์ ์ ๊ฐ๊น๊ณ .dockerignore๋ ์ฌ์ ํ ์์ .
์ด๊ฒ์ ๋ถ๋ช ํ ๋ฌด์ ๋์์์๋ ๋ถ๊ตฌํ๊ณ Linux ์์คํ ์์๋ ๋ณผ ์ ์์ต๋๋ค.
docker-compose ํ์ผ์์ ๋ถํ์ํ ๋ณผ๋ฅจ ์ฐธ์กฐ๋ฅผ ์ ๊ฑฐํ์ฌ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๋ค. Compose๋ ๋ณผ๋ฅจ์ ๋ํด .gitignore๋ฅผ ๋ฌด์ํฉ๋๋ค.
๋ํ npm 3+ ..๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด ์ฑ์ ์ ๊ทธ๋ ์ด๋ํด์ผํ์ง๋ง Windows ์ฌ์ฉ์์๊ฒ๋ง ์ ์ฉ๋ ์ ์์ต๋๋ค.
@ esc-rtn .dockerignore
ํ์ผ์ _build_ ๋์ ๋ฐ๋ชฌ์ผ๋ก ๋ณด๋ด์ง ์์์ผํ๋ ํ์ผ ๋ง ์ง์ ํฉ๋๋ค. "์คํ"์ค์ ๋ฐ์ธ๋ ๋ง์ดํธ ๋ ๋ณผ๋ฅจ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ํด๋น ์์น์ ๋ชจ๋ ํ์ผ์ ๋ณผ๋ฅจ์ผ๋ก ๋ง์ดํธํฉ๋๋ค (ํธ์คํธ์์๋ ๋ชจ๋ ํ์ผ).
Windows์์๋ ๋น์ทํ๊ฒ ๋ณด์
๋๋ค. docker build
๊ฐ ์์๋๋ก ์๋ํ๊ณ docker-compose
ํ์ง ์์ต๋๋ค.
README.md์ ๋ฉ๋ชจ์ ํจ๊ป GitHub์ ์์ ์๋ฅผ ๋ฃ์์ต๋๋ค. https://github.com/stekershaw/docker-compose-ignore
Compsoe 1.5.2๊ฐ ์ถ์ ๋ ํ .dockerignore
๋ํ ๋ ๋ค๋ฅธ ์์ ์ฌํญ์ด docker-py์ ์ ์ฉ๋์์ต๋๋ค. Compose 1.6.0 RC2 ๋ฆด๋ฆฌ์ค๋ฅผ ์ฌ์ฉํด๋ณด๊ณ ์ง๊ธ ์์ ๋์๋์ง ํ์ธํด ์ฃผ์๊ฒ ์ต๋๊น?
docker-compose ๋ฒ์ 1.6.0rc2๋ก ์๋ํ๊ณ a7636be๋ฅผ ๋น๋ํ์ญ์์ค.
๋ด ์ ์ฅ์์ ์ธ ๊ฐ์ ํ ์คํธ ์ผ์ด์ค๊ฐ ์๊ณ 1.5.2 ๋ ๊ฐ๊ฐ ์คํจํ์ต๋๋ค. ์ด์ 1.6.0rc2์์๋ ์ ์ธ ๋ ๋๋ ํ ๋ฆฌ์ ๋๋ ํ ๋ฆฌ์ ํ์ผ์ด์์ ๋ ํ๋๋ง ์คํจํฉ๋๋ค.
$ cat .dockerignore
files/test_dir
!files/test_dir/should_be_here_maybe
์ด ๊ฒฝ์ฐ docker build
๋ฐ docker-compose build
์ฌ์ด์์ ๋์ผํ ๋์์ด ๋ฐ์ํฉ๋๋ค.
.dockerignore
:
files/test_dir
!files/test_dir/should_be_here_maybe
docker-compose.yml
:
test:
build: .
Dockerfile
:
FROM busybox
COPY . /context
CMD ["find", "/context"]
$ docker version
Client:
Version: 1.10.0-rc1
API version: 1.22
Go version: go1.5.3
Git commit: 677c593
Built: Fri Jan 15 18:17:17 2016
OS/Arch: darwin/amd64
Server:
Version: 1.10.0-rc1
API version: 1.22
Go version: go1.5.3
Git commit: 677c593
Built: Fri Jan 15 18:17:17 2016
OS/Arch: linux/amd64
$ docker-compose version
docker-compose version 1.6.0rc2, build 695c692
docker-py version: 1.7.0-rc3
CPython version: 2.7.9
OpenSSL version: OpenSSL 1.0.1j 15 Oct 2014
$ mkdir -p files/test_dir
$ touch files/test_dir/should_be_here_maybe
$ find .
.
./.dockerignore
./docker-compose.yml
./Dockerfile
./files
./files/test_dir
./files/test_dir/should_be_here_maybe
$ docker build --no-cache -t 1607-docker-build .
Sending build context to Docker daemon 5.12 kB
Step 1 : FROM busybox
---> 0cb40641836c
Step 2 : COPY . /context
---> 859e12600100
Removing intermediate container 9067b263098b
Step 3 : CMD find /context
---> Running in 1ddc0a573492
---> b1b3beacf5f2
Removing intermediate container 1ddc0a573492
Successfully built b1b3beacf5f2
$ docker run 1607-docker-build
/context
/context/docker-compose.yml
/context/Dockerfile
/context/files
/context/files/test_dir
/context/files/test_dir/should_be_here_maybe
/context/.dockerignore
$ docker-compose build --no-cache
Building test
Step 1 : FROM busybox
---> 0cb40641836c
Step 2 : COPY . /context
---> d86507051d6d
Removing intermediate container 0af2cbf69b17
Step 3 : CMD find /context
---> Running in 8533dae3af74
---> 1f736ecb2b38
Removing intermediate container 8533dae3af74
Successfully built 1f736ecb2b38
$ docker-compose run test
/context
/context/docker-compose.yml
/context/Dockerfile
/context/files
/context/files/test_dir
/context/files/test_dir/should_be_here_maybe
/context/.dockerignore
์๋ ํ์ธ์ @aanand , ์๋ต ํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. ๊ทํ์ ๋จ๊ณ์ ๋ฐ๋ผ ๋์ผํ ๊ฒฐ๊ณผ๋ฅผ ์ป์์ต๋๋ค.
๊ทธ๋ฌ๋ ์ด์ ์ ์คํ ํ ํ
์คํธ์๋ files / test_dir์ ๋ ๋ค๋ฅธ ํ์ผ์ด ์์ต๋๋ค. files / test_dir์ ๋ค๋ฅธ ํ์ผ์ ์ถ๊ฐํ๋ฉด docker build
์๋ (์์๋๋ก) ์กด์ฌํ์ง ์์ง๋ง docker-compose
์๋ ์กด์ฌํ๋ค๋ ๊ฒ์ ์ ์ ์์ต๋๋ค.
$ touch files/test_dir/should_not_be_here
$ docker build --no-cache -t 1607-docker-build .
Sending build context to Docker daemon 5.12 kB
Step 1 : FROM busybox
---> b175bcb79023
Step 2 : COPY . /context
---> a23d9645c21c
Removing intermediate container 8eb2bb23c4db
Step 3 : CMD find /context
---> Running in d9fef847acd8
---> e52ae84b1250
Removing intermediate container d9fef847acd8
Successfully built e52ae84b1250
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
$ docker run --rm 1607-docker-build
/context
/context/Dockerfile
/context/files
/context/files/test_dir
/context/files/test_dir/should_be_here_maybe
/context/docker-compose.yml
/context/.dockerignore
$ docker-compose build --no-cache
Building test
Step 1 : FROM busybox
---> b175bcb79023
Step 2 : COPY . /context
---> 9df0cf4bfb69
Removing intermediate container 7820f982d59e
Step 3 : CMD find /context
---> Running in 06e1a0b89a45
---> 2c922dbc66d9
Removing intermediate container 06e1a0b89a45
Successfully built 2c922dbc66d9
$ docker-compose run test
ERROR: Interactive mode is not yet supported on Windows.
Please pass the -d flag when using `docker-compose run`.
$ docker-compose run -d test
dcitest_test_run_2
$ docker logs dcitest_test_run_2
/context
/context/Dockerfile
/context/files
/context/files/test_dir
/context/files/test_dir/should_not_be_here
/context/files/test_dir/should_be_here_maybe
/context/docker-compose.yml
/context/.dockerignore
์ด๊ฒ์ Windows (๋ด ์ ธ๋ก git bash ์ฌ์ฉ)์ด๋ฉฐ Docker compose 1.5.2 ๋ฐ 1.6.0rc2, docker 1.9.1๋ก ํ์ธ๋์์ต๋๋ค.
docker-compose 1.5.2 ๋ฐ docker 1.9.1๋ก Ubuntu 14.04์์ ๋์ผํ๊ฒ ์คํํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
# cat .dockerignore
files/test_dir
!files/test_dir/should_be_here_maybe
# find .
.
./.dockerignore
./docker-compose.yml
./files
./files/test_dir
./files/test_dir/should_not_be_here
./files/test_dir/should_be_here_maybe
./Dockerfile
# docker-compose build --no-cache
Building test
Step 1 : FROM busybox
---> b175bcb79023
Step 2 : COPY . /context
---> c533a0768d5e
Removing intermediate container 0c057fe8eb82
Step 3 : CMD find /context
---> Running in e8a0cf1f58d8
---> 175777486a25
Removing intermediate container e8a0cf1f58d8
Successfully built 175777486a25
# docker-compose run test
/context
/context/docker-compose.yml
/context/.dockerignore
/context/files
/context/files/test_dir
/context/files/test_dir/should_be_here_maybe
/context/Dockerfile
์์ง๋ ๋๋ถ๋ถ์ ์คํ๋ฅผ ๋ค๋ฃจ๊ณ ์์ต๋๋ค.
Docker ๋ฒ์ 1.10.1, ๋น๋ 9e83765
docker-compose ๋ฒ์ 1.6.0, ๋น๋ d99cad6
#docker-compose.yml
test:
build: ./cdn
#Dockerfile
FROM busybox
COPY ["content/","/test/"]
RUN find /test/ -maxdepth 1
#.dockerignore
**/.DS_Store
**/.git
**/.bowerrc
**/bower_components
**/node_modules
**/npm-debug.log
docker build .
์์๋๋ก ์ถ๋ ฅ
docker-compose build --no-cache test
๋ณต์ฌ
.dockerignore
์์ ์ฌํญ์ด ์์ต๋๋ค.๊ฐ์ฌํฉ๋๋ค @ shin-, ๋ถํํ๋ Windows ์ฉ Docker Toolbox์ docker-compose 1.6.2์์ ์ฌ์ ํ ๋ค๋ฅธ ๋์์ ๋ณผ ์ ์์ต๋๋ค.
$ docker-compose --version
docker-compose version 1.6.2, build e80fc83
$ find .
.
./.dockerignore
./docker-compose.yml
./Dockerfile
./files
./files/test_dir
./files/test_dir/should_be_here_maybe
./files/test_dir/should_not_be_here
$ cat .dockerignore
files/test_dir
!files/test_dir/should_be_here_maybe
$ docker-compose build --no-cache
Building test
Step 1 : FROM busybox
latest: Pulling from library/busybox
f810322bba2c: Pull complete
a3ed95caeb02: Pull complete
Digest: sha256:97473e34e311e6c1b3f61f2a721d038d1e5eef17d98d1353a513007cf46ca6bd
Status: Downloaded newer image for busybox:latest
---> 3240943c9ea3
Step 2 : COPY . /context
---> 85a65d7f861c
Removing intermediate container 386d3103d8ab
Step 3 : CMD find /context
---> Running in e5e29b5746c4
---> 2c2d57a899ea
Removing intermediate container e5e29b5746c4
Successfully built 2c2d57a899ea
$ docker-compose run -d test
dcitest_test_run_1
$ docker logs dcitest_test_run_1
/context
/context/Dockerfile
/context/files
/context/files/test_dir
/context/files/test_dir/should_be_here_maybe
/context/files/test_dir/should_not_be_here
/context/.dockerignore
/context/docker-compose.yml
๊ทธ๊ฒ์ ๋งค์ฐ ์ด์ํฉ๋๋ค. ๊ทธ๊ฒ์ ๋๋ฅผ ์ํด ํ์คํ ์๋ํฉ๋๋ค.
$ docker-compose build --no-cache
Building web
Step 1 : FROM busybox
---> 3240943c9ea3
Step 2 : COPY . /context
---> 3619871879ad
Removing intermediate container 08432f688579
Step 3 : CMD find /context
---> Running in 5bbcf987c9e7
---> cf2bff2c1416
Removing intermediate container 5bbcf987c9e7
Successfully built cf2bff2c1416
$ docker-compose run -d web
Creating network "testdockerignore_default" with the default driver
testdockerignore_web_run_1
$ docker logs testdockerignore_web_run_1
/context
/context/Dockerfile
/context/files
/context/files/test_dir
/context/files/test_dir/should_be_here
/context/docker-compose.yml
/context/.dockerignore
$ find .
.
./Dockerfile
./files
./files/test_dir
./files/test_dir/should_not_be_here
./files/test_dir/should_be_here
./docker-compose.yml
./.dockerignore
$ cat .dockerignore files/test_dir
!files/test_dir/should_be_here
์ฌ์ฉ์ ํ๊ฒฝ์์ pip show docker-py
์ ๊ฒฐ๊ณผ๋ ๋ฌด์์
๋๊น?
๋๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์๋ค๊ณ ์๊ฐํฉ๋๋ค.
Docker build .
๋๋ฅผ ์ํด ์๋ํฉ๋๋ค. ๊ทธ๋ฌ๋ ๋์ผํ ๋น๋๋ฅผ docker-compose.yml ํ์ผ๋ก ๋ฌถ์ผ๋ฉด ๋น๋๊ฐ ์์๋ฉ๋๋ค. ๋ด .dockerignore ํ์ผ์์ ๋ ธ๋ ๋น๋๋ฅผ ์ํด node_modules ๋๋ ํ ๋ฆฌ๋ฅผ ์ ์ธํ๊ณ ์์ต๋๋ค. ์ด๊ฒ์ ๋ด docker-compose.yml์ ๊ด๋ จ ์น์ ์ ๋๋ค.
web:
build: ./app
ports:
- "8080:8080"
links:
- mongodb
์ต์ ๋ฒ์ ์ docker-compose๋ฅผ ์คํํ๊ณ ์๋ค๊ณ ์๊ฐํฉ๋๋ค.
>docker-compose version
docker-compose version 1.6.2, build e80fc83
docker-py version: 1.7.2
CPython version: 2.7.11
OpenSSL version: OpenSSL 1.0.2d 9 Jul 2015
Windows 10, x64๋ฅผ ์คํํ๊ณ ์์ต๋๋ค.
WIndows ๊ด๋ จ ๋ฌธ์ , ๊ฒฝ๋ก ๊ตฌ๋ถ ๊ธฐํธ๊ฐ์์ ์ ์์ต๋๊น?
์ด๊ฒ์ด ๊ฒฝ๋ก ๊ตฌ๋ถ์์ ๊ด๋ จ์ด ์๋์ง ํ์ธํ๋ ๋ฐฉ๋ฒ์ ๋ชจ๋ฆ ๋๋ค.
ํ ์คํธ ๋๋ ๊ธฐํ ์ง์์ด ๊ฐ๋ฅํ์ง ์๋ ค์ฃผ์ญ์์ค. ์ง๊ธ์ ๋น๋ ์ ์ "๋ฌด์ ๋"ํด๋๋ฅผ ํ๋ก์ ํธ ๋๋ ํ ๋ฆฌ ๋ฐ์ผ๋ก ์ฎ๊ธฐ๋ ๋ฐฐ์น ํ์ผ์ด ์์ต๋๋ค. ๋ถ๋ช ํ๋ณด๊ธฐ ํํฉ๋๋ค.
๋น์ ์ ๋์์ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.
์์ ์ฑ์ ์ํด ์ด๊ฒ์ ๋ด .dockerignore ํ์ผ์ ๋๋ค.
**/node_modules
์ํ! ๋ฌธ์ ๋ฅผ ์ผ์ผํค๋ ๊ฒ์ glob ํจํด์ ๋๋ค. "** /"๋ฅผ ์ ๊ฑฐํ๋ฉด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์์ต๋๋ค.
ํน์ ๋ฌธ์ ์ ๋ํ ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ์์ง๋ง ๋ฒ๊ทธ๊ฐ ์๋ค๋ ์ฌ์ค์ ์ฌ์ ํ โโ๋จ์ ์์ต๋๋ค. ์ ์ด๋ glob ํจํด ** /์ docker-compose๋ก ์ ๋๋ก ๊ตฌ๋ฌธ ๋ถ์๋์ง ์์ง๋ง ์ผ๋ฐ docker ๋น๋ ๋ช ๋ น์์๋ ์ ๋๋ก ์๋ํฉ๋๋ค. ๋ค๋ฅธ glob ํจํด์ ์๋ํ๊ฑฐ๋ ์๋ํ์ง ์์ ์ ์์ต๋๋ค.
@bfirsh ๋ฐ ๊ด์ฌ์ ๊ฐ์ง๋งํ ๋ค๋ฅธ ๋ชจ๋ ์ฌ๋ :
๋ค์๊ณผ ๊ฐ์ ์ ๋์ ์ผ๋ก ๊ฐ๋จํ .dockerignore๊ฐ ์์ต๋๋ค.
readonly-data
.dockerignore๋ ์๋ํ์ง ์์ผ๋ฉฐ (๋น๋ ์ปจํ ์คํธ ํด๋์ ๋ ํด๋๊ฐ ๋ฐ๋ชฌ์ ์ ๋ก๋๋๊ณ _forever_ ๊ฑธ๋ฆฝ๋๋ค) Linux์ ์์ต๋๋ค. ํ์ฌ 1.6.2๋ก ์ ๋ฐ์ดํธํ์ง๋ง ๋ณ๊ฒฝ ์ฌํญ์ ์์ต๋๋ค. ๋์ผํ ์ฆ์์ผ๋ก ๋ค๋ฅธ ๋ฌธ์ ๊ฐ ๋ฐ๊ฒฌ๋์ง ์๋ ํ,์ด ๋ฌธ์ ๊ฐ Windows ๊ด๋ จ ๋ฌธ์ ๊ฐ ์๋ ๊ฒ ๊ฐ๋ค๋ ์ ์ ๋ค์ ๋ฐ๋ณตํ๊ฒ ์ต๋๋ค ..
+1, Linux์์๋ ๋์๊ฒ ์์๋จ-Windows ๊ด๋ จ ๋ฌธ์ ๋ผ๊ณ ์๊ฐํ์ง ๋ง์ญ์์ค.
@JonasT @nicbarker ์๊ฐ์ด ์ค๋ ๊ฑธ๋ฆฌ๋ ๊ฒ ์ธ์ .dockerignore
์ด๋ฆ์ด ์ง์ ๋ ํด๋๊ฐ ์
๋ก๋๋๊ณ ์๋์ง ์ด๋ป๊ฒ ํ์ธํฉ๋๊น? ํ๋ฅด๋ณผ์ ํ์ธํ๋ ๋ฐฉ๋ฒ์ด ์๋ค๋ฉด ๋ก์ปฌ์์ ๋ฌธ์ ๋ฅผ ์ฌํํ๋ ๋ฐ ์ฌ์ฉํ๊ณ ์ถ์ต๋๋ค. ๊ทธ๋๋ก docker-py์ ๋๋ฒ๊ทธ๋ฅผ ์ถ๊ฐํ์ง๋ง ์ฌ์ ํ ์ฌํ ํ ์ ์์ต๋๋ค.
$ pip list | grep docker
docker-compose (1.7.0.dev0, /Users/aanand/work/docker/compose)
docker-py (1.8.0rc2, /Users/aanand/work/docker/docker-py)
$ find .
.
./.dockerignore
./docker-compose.yml
./Dockerfile
./include.txt
./livedata
./livedata/exclude.txt
./readonly-data
./readonly-data/exclude.txt
$ cat .dockerignore
livedata
readonly-data
$ cat Dockerfile
FROM busybox
COPY . /data
$ docker-compose --verbose build --no-cache
<unrelated output>
docker.utils.utils.tar: Writing tar file to <open file '<fdopen>', mode 'w+b' at 0x1090f26f0>
docker.utils.utils.tar: Adding .dockerignore
docker.utils.utils.tar: Adding Dockerfile
docker.utils.utils.tar: Adding docker-compose.yml
docker.utils.utils.tar: Adding include.txt
docker.utils.utils.tar: Done
<unrelated output>
@aanand ์์ํ๊ธฐ๊น์ง ์ ๋ง ์ค๋ ์๊ฐ์ด ๊ฑธ๋ฆฌ๋ฉฐ Dockerfile์ ./context๋ก ์ด๋ํ๊ณ ๋ค๋ฅธ ๋ณ๊ฒฝ์์ด "build : ./context/"๋ฅผ ์ฌ์ฉํ๋ฉด ์ฆ์ ์์ฒญ๋๊ฒ ๋น ๋ฆ ๋๋ค. ๋ํ์ด ๋ฌธ์ ๊ฐ ์ฒ์ ๋ํ ๋ฌ์ ๋ "๋์ปค ๋น๋"๋ฅผ ์ฌ์ฉํ์ฌ ์๋์ผ๋ก ๋์ปค ๋น๋๋ฅผ ์๋ํ์ผ๋ฉฐ ๋ํ ์ฆ๊ฐ์ ์ด์์ต๋๋ค.
๊ทธ๊ฒ์ ์ค์ ๋ก ๋ฌธ์ ๋ฅผ ํ์ธํ์ง ์์ต๋๋ค. ํ๋ก์ ํธ ๋ฃจํธ์ ๋ค๋ฅธ ํฐ ๋๋ ํฐ๋ฆฌ๊ฐ์๋ ๊ฒฝ์ฐ ๋น๋๋ฅผ ./context
์ด๋ํ๋ฉด ์๋๊ฐ ๋นจ๋ผ์ง๋๋ค.
@dnephin ๊ฑฐ๊ธฐ์ ๋ด๊ฐ ํด๊ฒฐ ๋ฐฉ๋ฒ์ผ๋ก ๊ด๊ณ ํ "์ปจํ ์คํธ"์์ฒด์ ์ธ ๊ฐ์ ์์ ํ ์คํธ ํ์ผ์ ์ ์ธํ๊ณ ๋ ๋ค๋ฅธ ํด๋๊ฐ ์์ต๋๋ค.
@JonasT ํฌํจ ๋๋ ํฐ .git
๋๋ ํ ๋ฆฌ๊ฐ์์ ์ ์์ต๋๊น?
ํธ์ง : NVM, ์๋ชป๋ rsync'ed
๋ณต์ฌ>.> ์ฃ์กํฉ๋๋ค .. ํ์ธํ๊ธฐ ๋๋ฌธ์ ์ค์ ๋ก ๋๋ ํ ๋ฆฌ๋ฅผ ๋์น ๋งํผ ์ด๋ฆฌ์์ ๊ฒ ๊ฐ์ต๋๋ค.
์ค์ ๋ก ์ด์ Docker-compose ๋ฒ์ ์์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ฌ ๋ ์์ธํ ์กฐ์ฌํ์ง๋ง ์ค์ ๋ก ์ต๊ทผ์ Dockerpy ์ ๋ฐ์ดํธ๋ก ์์ ๋ ํน์ ์ธ์คํด์ค๊ฐ์์ ์ ์์ต๋๋ค.
์ด๊ฒ์ด Windows ๋ฌธ์ ๋ก ๋์๊ฐ์ญ๋๊น? :)
์๋
ํ์ธ์,
๋๋ ๋ฆฌ๋
์ค๋ฅผ ๊ฐ์ง๊ณ ์๊ณ , 1.6.2๋ฅผ ์์ฑํ๊ณ , ๋์ปค 1.10.3์ ... ์ ํํ ๊ฐ์ ๋ฌธ์ ์
๋๋ค. docker๋ .dockerignore
ํ๊ณ compose๋์ด๋ฅผ ๋ฌด์ํฉ๋๋ค.
@ulrichSchreiner ์ฌํ ๋จ๊ณ๋ฅผ ์ ๊ณต ํ ์ ์์ต๋๊น?
์๋ ํ์ธ์,
์ฌ๊ธฐ์ ์์ ์ด ์์ต๋๋ค (https://gist.github.com/ulrichSchreiner/566815cea26ce55b95207e7795cf6962). .dockerignore
์๋ **/node_modules
๊ฐ ํฌํจ๋์ด ์์ต๋๋ค. Dockerfile์ t1/a/b/c/node_modules
ํ์ ํด๋์ ํ์ผ์ ์ถ๊ฐํฉ๋๋ค.
"docker build ..."๋ก ๋น๋ํ๋ฉด ์ถ๊ฐ ํ ํ์ผ์ด ์๊ธฐ ๋๋ฌธ์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค ( .dockerignore
์ ํจํด ๋๋ฌธ์ ์ฌ๋ฐ๋ฅด๊ฒ ๋ฌด์ ๋จ). ์์ ์ ๋ง์ง๋ง ํ์ผ์์ ์ถ๋ ฅ์ ๋ณผ ์ ์์ต๋๋ค.
๊ทธ๋ฌ๋ ์ฃผ์ด์ง "docker-compose.yml"๋ก ๋น๋ํ๋ฉด ์ฑ๊ณต์ ์ผ๋ก ๋น๋๋ฉ๋๋ค-> docker-compose๋ .dockerignore
ํ์ผ์ ๋ฌด์ํฉ๋๋ค.
node_modules
๋๋ ํ ๋ฆฌ๊ฐ ์๋ฐฑ ๋ฉ๊ฐ
๋๋ ์ฌ์ฉํ๋ค
docker-compose version 1.6.2, build 4d72027
์ข์, ๋๋ ์ด๊ฒ์ ์ฌํ ํ ์์๋ค. docker-py๊ฐ **/
๊ท์น์ ๋ฒ๊ทธ๊ฐ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
IIRC, **
๊ตฌ๋ฌธ์ ๋ํ ์ง์ ๋ถ์กฑ์ .dockerignore
๊ตฌํ์ ์๋ ค์ง ์ ํ ์ฌํญ์
๋๋ค. https://github.com/docker/docker-py/pull/721#issuecomment -135065043 ์ฐธ์กฐ
์ฌ๊ธฐ์๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. .dockerignore
๋ docker-compose์ ํจ๊ป ์ฌ์ฉํ ๋ ๋ฌด์๋ฉ๋๋ค.
docker-compose version 1.6.2, build 4d72027
OSX
./.dockerignore
./Dockerfile (symlink to ./server/docker/cms/Dockerfile)
./server/docker/docker-compose.yml
.dockerignore์ ๋ด์ฉ
./.git
./.vagrant
.vagrant๋ 16GB์ด๋ฏ๋ก ์ด๊ฒ์ ์ฐ๋ฆฌ์๊ฒ "ํฐ ๊ฑฐ๋ (tm)"์ ๋๋ค.
์ฃ์กํฉ๋๋ค,
docker-machine version 0.7.0, build a650a40
docker-compose version 1.7.0, build 0d7bf73
docker-py version: 1.8.0
CPython version: 2.7.9
OpenSSL version: OpenSSL 1.0.1j 15 Oct 2014
Client:
Version: 1.11.1
API version: 1.23
Go version: go1.5.4
Git commit: 5604cbe
Built: Tue Apr 26 23:44:17 2016
OS/Arch: darwin/amd64
Server:
Version: 1.11.1
API version: 1.23
Go version: go1.5.4
Git commit: 5604cbe
Built: Wed Apr 27 00:34:20 2016
OS/Arch: linux/amd64
@lattwood ๋ฒ๊ทธ์ฒ๋ผ ๋ณด์
๋๋ค //github.com/docker/docker-py/pull/1065 ์์ ์์ ํ์ต๋๋ค . ์ง๊ธ์ ํจํด์์ ์ ํ ./
๋ฅผ ์ ๊ฑฐ ํ ์ ์์ผ๋ฉฐ ์๋ํฉ๋๋ค.
๊ฐ์ฌ!
Ubuntu 14.04์์ ์คํ๋๋ ๋ด dockerignore๋ ๋จ์ํ **/always_restart.txt
์
๋๋ค. ์ผ๋ฐ docker build
(v1.11.2)์์๋ ์ปจํ
์ด๋์ ํ์ผ์ด ํ์๋์ง ์์ง๋ง Compose (v1.7.1)์์๋ ๋ณผ ์ ์์ต๋๋ค.
Edit1 : docker-py
๊ฐ ์ด์ค ๋ณํ ํ๊ธฐ๋ฒ์ ํ
์คํธํ์ง ์๋ ๊ฒ์ฒ๋ผ ๋ณด์ด๋ฉฐ https://github.com/docker/docker-py/blob/1.9 ์ค ํ๋๋ฅผ ์ฒ๋ฆฌํ์ง ์์ ๊ฐ๋ฅ์ฑ์ด ๋์ต๋๋ค
Edit2 : */tmp/always_restart.txt
ํจํด์ ์ฌ์ฉํ๋ฉด Compose์ ํจ๊ป ์๋ํ๋ฏ๋ก **
ํจํด์ ํน๋ณํ ๋ฌด์๋ฉ๋๋ค.
@ agilgur5 ๋ง์ต๋๋ค. ์ด๊ฒ์ docker-py์ ์๋ ค์ง ๋ฌธ์ ์ ๋๋ค. ๋๋ ๊ทธ๊ฒ์ ์ถ์ ํ๊ธฐ ์ํด https://github.com/docker/docker-py/issues/1117 ์ ๋ง๋ค์์ต๋๋ค.
DOCKERFILE์ ์ถ์
ํ ํด๊ฒฐ ๋ฐฉ๋ฒ :
๊ตฌ๋ฌธ ๋ถ์์ ์ํด git-check-ignore ๋ฅผ ์ฌ์ฉํ์ฌ (๋ฐ๋ผ์ git init
), ๋ณต์ฌ ํ ๋ฌด์ํด์ผํ๋ ๋ชจ๋ ๊ฒ์ ์ญ์ ํฉ๋๋ค.
COPY
s (๋๋ ADD
s) ๋ค์ ์์ด์ผํ๋ ์ฐ๋ฆฌ์ ๊ฒฝ์ฐ์๋ ์ํ์ง ์๋ ํ์ผ์ด ๋ค์ ์๊ฒผ์ต๋๋ค.
RUN mkdir /app/
WORKDIR /app/
# ...
# all the COPYs
# ...
RUN git init
COPY ./.dockerignore /app/
RUN mv .dockerignore .gitignore
RUN DEL_ME=$(find . -print0 | xargs -0) && echo Forcing deletion of .dockerignore files && git check-ignore --no-index $DEL_ME > tmp.txt
RUN DEL_ME=$(cat tmp.txt | xargs) && echo DELETING: $DEL_ME tmp.txt && rm -f -d -r $DEL_ME tmp.txt
.gitignore์์ ํ์ผ์ ์ ๊ฑฐํ๋ ค๋ฉด (์ด์ ๊ฐ ์๊ธฐ ๋๋ฌธ์)
COPY ./.gitignore /app/
COPY ./.dockerignore /app/
RUN DEL_ME=$(find . -print0 | xargs -0) && echo gitignore && git check-ignore --no-index $DEL_ME > tmp.txt
RUN rm .gitignore && mv .dockerignore .gitignore
RUN DEL_ME=$(find . -print0 | xargs -0) && echo dockerignore && git check-ignore --no-index $DEL_ME >> tmp.txt
RUN DEL_ME=$(cat tmp.txt | xargs) && echo DELETING: DEL_ME tmp.txt && rm -f -d -r $DEL_ME tmp.txt
๊ธฐ๋ณธ์ ์ผ๋ก ๋ฎ์ด ์ฐ์ง ์์ผ๋ ค๋ ์ปจํ
์ด๋ ๋๋ ํ ๋ฆฌ๋ฅผ ๋์ดํ์ฌ docker-compose.yml
๋ฐ์ดํฐ ๋ณผ๋ฅจ์ ์ฌ์ฉํ์ฌ ์ด์ ๋ํ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ฐพ์ ๊ฒ ๊ฐ์ต๋๋ค. ์ฐ๋ฆฌ์ ๊ฒฝ์ฐ ์ปจํ
์ด๋์ node_modules
๋๋ ํฐ๋ฆฌ๋ฅผ ์ ์งํ๋ ค๊ณ ํ์ต๋๋ค.
๋ฐ๋ผ์ docker-compose.yml
์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
my_app:
build: ./my_app
volumes:
- ./my_app:/app
# prevent the mounting above from overwriting the following
- /app/node_modules
volumes
๊ฐ์ ๋ฌด์์ ์ค๋ณต ์ํ .dockerignore
ํ์ง๋ง ์ง๊ธ์ ๊ฐ๊ณ ์ฐ๋ฆฌ๋ฅผ ์ป์ ์ ...
์ด ๋ฌธ์ ์ ๋ํ ๋์ ์์ค์ ์ ์์ด ์์ต๋๋ค.
์ด ๋ฌธ์ ๋ฅผ "[๋ฉํ ๋ฌธ์ ] : .dockerignore ๊ท์น์ ์๋ชป๋ ์ฒ๋ฆฌ"(๋๋ "[์ถ์ ๋ฌธ์ ] : ์๋ชป๋ ์ฒ๋ฆฌ ...")์ ๊ฐ์ด ๋ค์ ์์ฑํ๊ฑฐ๋ ๋จ์ํ ์ปฌ๋ ์
์ ์ํด์ด ๋ฌธ์ ๋ฅผ ์ข
๋ฃํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ๋ ์๊ณ ์คํ ๊ฐ๋ฅํ ๋ฌธ์ ์
๋๋ค. ์ด๊ฒ์ (1) Docker compose๊ฐ .dockerignore
ํ์ผ (ํ์ฌ ์ด์ ์ ๋ชฉ์ด ๋งํ๋ ๊ฒ)์ "๋ฌด์"ํ๋ ๊ฒ์ด ์๋๊ธฐ ๋๋ฌธ์
๋๋ค. ๋จ์ํ ๊ท์น์ ์ฌ๋ฐ๋ฅด๊ฒ ๊ตฌํํ์ง ์์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ (2)์ด ๋ฌธ์ ์๋ ์ฌ๋ฌ ๋ถ๋ถ์ด ์์ต๋๋ค. ์ด๊ฒ์ ๋จ์ง ํ๋์ ๋ฌธ์ ๊ฐ ์๋๋๋ค. ์๋ฅผ ๋ค์ด,์ด ์ด๊ฒ ( **
์ฒ๋ฆฌ) ๋ฐ ์ด ์๋ก์ด ๋ ๊ทธ๋ฅ ์ ์ถ (๋ง์ง๋ง ์ค ์ฐ์ ์์). ๊ทธ๋ฆฌ๊ณ ๋ ๋ง์ ๊ฒ์ด์์ ์ ์์ต๋๋ค.
์ด ๋ฌธ์ ์ค๋ ๋๊ฐ ๋๋ฌด ๊ธธ๊ธฐ ๋๋ฌธ์ (๊ด๋ฒ์ํ ๋ฌธ์ ์์ญ์ ๋ค๋ฃจ๊ธฐ ๋๋ฌธ์) ํด๊ฒฐํด์ผํ๋ ๊ฐ๋ณ ๋ฌธ์ ๋ฅผ ์ค๋ ๋ ๋ด์์ ์ฐพ๊ธฐ๊ฐ ์ด๋ ต์ต๋๋ค. ์ผ๋ฐ์ ์ธ ".dockerignore๊ฐ ์๋ํ์ง ์๋ ๊ฒ ๊ฐ์"๋ฌธ์ ์๋ ๋ฌ๋ฆฌ, ๋ณ๋๋ก ํด๊ฒฐํ ์์๋ ์ ์ ์ ๋ ๋ฌธ์ ๋ฅผ ์ ์ถํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ํ์ฌ ํํ ๋๋๋ก์ด ๋ฌธ์ ๋ Python ๊ตฌํ์ด ์ฐธ์กฐ ๊ตฌํ๊ณผ ํจ๋ฆฌํฐ๋ฅผ ๊ฐ์ง ์ ์๊ธฐ ๋๋ฌธ์ ์ ๋๋ก ๋ซํ์ง ์์ ์ ์์ต๋๋ค.
๋๋ **/**/node_modules
ํ์ง๋ง ์ด๊ฒ์ด ์๋ํ์ง ์๋๋ค๋ ๊ฒ์ ์์ ๋์ต๋๋ค. ๊ทธ๋์์ด ๋ฒ๊ทธ๋ฅผ ์์ ํ๊ธฐ ์ํด ํ์ ํ๋ก์ ํธ์ ๊ฐ node_modules ๋๋ ํ ๋ฆฌ๋ฅผ ์ ์ํ์ต๋๋ค.
์ด ํซํฝ์ค ์ด์ ์๋ npm ์ข ์์ฑ์ด ์ด๋ฏธ ์๊ธฐ ๋๋ฌธ์ ์ค์นํ ๋ "์ก์ธ์ค ๊ถํ ์ค๋ฅ"๊ฐ ๋ฐ์ํ์ต๋๋ค (์๋ํ์ง ์๋ dockerignore ํ์ผ๋ก ๋ณต์ฌํ์ฌ ๋ฐ์).
๊ฐ์ ๋ฌธ์ ์ ๋๋ค.
macOS Sierra 10.12.2
Docker ๋ฒ์ 1.12.5, ๋น๋ 7392c3b
docker-compose ๋ฒ์ 1.9.0, ๋น๋ 2585387
**
ํจํด ๋ฌธ์ ๋ 1.11.2์์ ์์ ๋์ด์ผํฉ๋๋ค.
# 3931 ๋ฐ # 3886์์ ๋ณ๋๋ก ์ถ์ ๋๋ ๋ง์ง๋ง ์ค ์ฐ์ ์์๊ฐ์๋ ๋ฌธ์ ์ ๊ฐ์ ๋ฏธํด๊ฒฐ ๋ฌธ์ ๊ฐ์์ ์ ์์ต๋๋ค. ์ถ๊ฐ ์
๋ฐ์ดํธ๋ ์ด๋ค์ ์ฐธ์กฐํ์ญ์์ค.
docker-compose๊ฐ ๋ด .dockerignore
) ๋ฌด์ํ๋์ง ๋๋ ์ ๋๋ก ํด์ํ์ง ๋ชปํ๋์ง ํ์คํ์ง ์์ต๋๋ค (์ ์๋ํ๋ docker์๋ ๋ฌ๋ฆฌ). ์ด๊ฒ์ด ๋ด๊ฐ ์ฌ๊ธฐ์ ๋์ฐฉํ ๋ฐฉ๋ฒ์
๋๋ค : http://stackoverflow.com/questions/42883596/equivalent-builds-dont-behave-the-same
๋ค์์ ๋ด .dockerignore
ํ์ผ์
๋๋ค (๋ฌธ์ ๊ฐ ๋ฌด์์ธ์ง ์์๋ผ ์์๋ ๊ฒฝ์ฐ).
$ cat .dockerignore
*
!www
!app
!inc
*/node_modules
*/bower_components
**/*.log
**/Dockerfile
**/.gitignore
๋ด docker-compose build
๊ฐ .dockerignore
ํ์ผ์ ์์ ํ ๋ฌด์ํ๋ ๊ฒ ๊ฐ์ต๋๋ค.
docker build
๊ฐ ์์๋๋ก ์๋ํฉ๋๋ค.
$ docker-compose version
docker-compose version 1.14.0, build c7bdf9e
docker-py version: 2.3.0
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t 3 May 2016
๋ด .dockerignore
์ (๋) ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
.bundle
.git
.gitignore
test
tmp
log
์ฌ๊ธฐ์ ํน๋ณํ ๊ฒ์ ์์ต๋๋ค.
Ubuntu 16.04๋ฅผ ์ฌ์ฉํ๊ณ ์์ง๋ง ๊ทธ๊ฒ ์ค์ํ์ง ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
BTW : ๋๊ตฐ๊ฐ docker-compose build
๊ฐ docker build
์ ๊ฐ์ ์ฝ๋๋ฅผ ์ฌ์ฉํ์ฌ Dockerfile
์ ๊ทธ ๋ชจ๋ ๊ฒ์ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง๋ฅผ ๋น๋ํ์ง ์๋ ์ด์ ๋ฅผ ์ค๋ช
ํ ์ ์์ต๋๊น? ๋ช
๋ฐฑํ ์ฝ๋ ์ค๋ณต์ด์๋ ์ด์ ๋ ๋ฌด์์
๋๊น (์ด ๋ฌธ์ ๊ฐ ๋ณด์ฌ ์ฃผ๋ฏ์ด ์ ๋๋ก ์๋ํ์ง ์์)?
์ด ๋ฌธ์ ๊ฐ ์ข ๊ฒฐ ๋ ์ด์ ๋ ๋ฌด์์ด๋ฉฐ ์ด๋ป๊ฒ ๋ค์ ์ด ์ ์์ต๋๊น? ์ํํธ์จ์ด๊ฐ ๋ช ํํ๊ฒ ์์๋์์ผ๋ฉฐ ์์ ํด์ผํฉ๋๋ค.
์. ๊ฐ์ฌํฉ๋๋ค ์ . ํด๊ฒฐ ๋ ๊ฒ์ด๋ค ๊ธฐ์๋ค
๋๋ ์ ์ ๋ ๋ฌธ์ # 3931 ๋ฐ # 3886์ ์ฝ์์ง๋ง ๋ด .dockerignore๊ฐ ํน๋ณํ์ง ์์ ๋ด ๋ฌธ์ ๋ฅผ ์ ํํ๊ฒ ๋งคํ ํ ์ ์์์ต๋๋ค.
๋๋ ๋๋ฅผ ์ํด ์ ํ ์ผํ์ง ์์ผ๋ฉฐ ๋ด .dockerignore์ ๋ฌด์์ด ์๋์ง๋ ์ค์ํ์ง ์์ต๋๋ค.
๋๋ฌด ๋ฉ์ฒญ ํด, ๋ด ์ค์ ์์ด. : dizzy_face :
์ฝ๋๋ฅผ ๋ณผ๋ฅจ์ผ๋ก ๋ง์ดํธํ๊ธฐ ๋๋ฌธ์ ๋ฌด์ํ ๊ฒ์ด ์๋ค๋ ๊ฒ์ด ๋ถ๋ช
ํฉ๋๋ค. ๊ทธ ์ฃ์กํฉ๋๋ค.
app:
build: .
container_name: my_app
volumes:
- .:/my_app
ํด๊ฒฐ๋์ง ์์ ๊ฒ ๊ฐ์ต๋๊น?
version: '3.4'
services:
ui:
build:
context: ./source/ui
dockerfile: Dockerfile
target: development
command: bash -c "yarn dev"
ports:
- '9091:9091'
- '9092:9092'
expose:
- '9091'
- '9092'
volumes:
- ./source/ui:/app
- node-modules:/app/node_modules
environment:
- PORT=9091
- HMR_PORT=9092
- NODE_ENV=development
- API_HOST=api.docker:7001
volumes:
node-modules:
in source/ui/.dockerignore:
node_modules
dist
```
๊ทธ๋ฌ๋ ๋ ํด๋ ๋ชจ๋ ๊ฒฐ๊ตญ ์์ฑ๋ฉ๋๋ค ...
๋๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์๋ค. ๋ด๊ฐ ์ด์ ์์ฑ ๋ฒ์ ์ ์๋ค๋ ๊ฒ์ ์์์ ๋. docker-compose version 1.22.0-rc1, build e7de1bc3
์
๋ฐ์ดํธ๋์์ต๋๋ค.
๋ฌธ์ ๋ debian / ubuntu์ ํฌํจ ๋ ์์ฑ ๋ฒ์ ์ด ๋๋ฌด ์ค๋๋์๋ค๋ ๊ฒ์ ๋๋ค.
์ด์ ๋ ์ ์๋ํ์ง๋ง docker build
์ฒ๋ผ ์ฌ์ ํ ๋์ผํ์ง๋ ์์ต๋๋ค.
์์ง ํด๊ฒฐ๋์ง ์์์ต๋๋ค. Mac ์ฉ Docker, ์ต์ ๋ฒ์ ์คํ (Docker 18.03.1-ce-mac65).
๋ด .dockerignore :
**/package-lock.json
**/node_modules
๊ทธ๋ฌ๋ ๋ ๋ค docker-compose๋ฅผ ์ฌ์ฉํ ๋ ์ปจํ ์ด๋๋ก ์ ๋ฌ๋ฉ๋๋ค.
https://github.com/docker/docker-py/pull/2065 ๋ 1.22.0 RC2์ ์์ผ๋ฉฐ์ด๋ฅผ ํด๊ฒฐํด์ผํฉ๋๋ค.
Mac ์ฉ Docker ๋ฒ์ 18.06.1-ce-mac73 (26764)
์ ์ฌ์ฉํ๊ณ ์๋๋ฐ ๋ฒ๊ทธ๊ฐ ์ฌ์ ํ ์์ต๋๋ค.
๋๋ ์ฌ์ฉํ๊ณ ์๋ค :
docker-compose ๋ฒ์ 1.22.0, ๋น๋ f46880f
Docker ๋ฒ์ 18.06.1-ce, ๋น๋ e68fc7a
Ubuntu 16.04 Xenial ๋ฐ docker-compose ๋น๋์์ ์คํํ๋ฉด ๋ค์ .dockerignore๊ฐ ๋ฌด์๋ฉ๋๋ค.
**/*.jpg
**/*.png
**/*.pyc
**/*.solverstate
**/*.caffemodel
**/*.tgz
**/.pytest_cache
**/*__pycache__*
**/.git
**/node_modules
*.egg-info
.eggs
*Dockerfile*
build
dist
์ด์ ์ด์ค ๋ณํ๋ฅผ ํด์ํด์ผํ๋ฏ๋ก ์์ธ์ด ๋ฌด์์ธ์ง ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ๊ฐ์ ๋ฌธ์ ๊ฐ์๋ ์ฌ๋์ด ์์ต๋๊น?
์ด์ ์ด์ค ๋ณํ๋ฅผ ํด์ํด์ผํ๋ฏ๋ก ์์ธ์ด ๋ฌด์์ธ์ง ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ๊ฐ์ ๋ฌธ์ ๊ฐ์๋ ์ฌ๋์ด ์์ต๋๊น?
๋์ผํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค ( **/.tox
).
๋๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์๋ค. ๋๋ ๋ค๋ฅธ ๋งฅ๋ฝ์ ์ฌ์ฉํฉ๋๋ค.
docker-compose.yml ์ ์ฑ ๋ฃจํธ ๊ฒฝ๋ก์ ๋ฐฐ์น๋๋ฉฐ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
services:
api:
build:
context: ./docker/api
๋ด ํ์ผ ํธ๋ฆฌ :
- app/
-- docker/
--- api/
---- .dockerignore <- it works!
-- docker-compose.yml
-- .dockerignore <- it does not work for contexts
์ข์ ํ๋ฃจ ๋์ธ์!
@ zymtx5g79k ์ ์๊ฒ ํจ๊ณผ๊ฐ ์์ต๋๋ค.
- .dockerignore
- docker/
-- development/
--- docker-compose.yml
version: '3'
services:
web:
build:
context: ../../.
@rodrigobdz , ํ์ธํ์๊ธฐ ๋ฐ๋๋๋ค :
docker-compose.yml :
services:
api:
build:
context: ./../../
version: '3'
.dockerignore :
/docker
ํ์ผ ๊ตฌ์กฐ :
- docker/
-- api/
--- docker-compose.yml
- .dockerignore
์ฌ์ ํ ๋์ผํ ๊ฒฐ๊ณผ๋ก .git
๋๋ ํฐ๋ฆฌ๋ ์๋ฅผ ๋ค์ด ์ปจํ
์ด๋์ ์์ต๋๋ค. ์ฌ๊ธฐ์ ๋ด .dockerignore๋ฅผ ๊ฒ์ํ๊ฒ ์ต๋๋ค. ์๋ง๋ ๋ฌธ์ ์์ฒด๊ฐ์์ ์ ์์ต๋๋ค.
# Custom
docker-compose.yml
docs/
livereload.js*
yarn-error.log
v8-compile-cache-0
# vim
*.swp
.git
.gitignore
README.md
@rodrigobdz ๋ฌธ์ ๋ฅผ ์ฌํ ํ ์ ์์ต๋๋ค (docker compose ๋ฒ์ 1.22.0 ์คํ).
์ํ ์ค๋น;
mkdir repro-1607 && cd repro-1607
mkdir -p docker/development/
mkdir -p ./.git/this-is-a-git-repo
echo "this is README.md" > README.md
cat > docker/development/docker-compose.yml -<<EOF
version: '3'
services:
web:
build:
context: ../../.
EOF
cat > ./.dockerignore -<<EOF
# Custom
docker-compose.yml
docs/
livereload.js*
yarn-error.log
v8-compile-cache-0
# vim
*.swp
.git
.gitignore
README.md
EOF
cat > Dockerfile -<<EOF
FROM alpine
RUN apk add --no-cache tree
COPY . /foobar/
CMD tree -a /foobar/
EOF
docker-compose๋ฅผ ์ฌ์ฉํ์ฌ ๋น๋ํ์ญ์์ค.
cd docker/development/
docker-compose build --no-cache
Building web
Step 1/4 : FROM alpine
---> 11cd0b38bc3c
Step 2/4 : RUN apk add --no-cache tree
---> Running in 8767bc07dad9
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
(1/1) Installing tree (1.7.0-r1)
Executing busybox-1.28.4-r0.trigger
OK: 5 MiB in 14 packages
Removing intermediate container 8767bc07dad9
---> 3916d3b689bb
Step 3/4 : COPY . /foobar/
---> 76ab68d75f88
Step 4/4 : CMD tree -a /foobar/
---> Running in 9891624b3cab
Removing intermediate container 9891624b3cab
---> d22b81d149f2
Successfully built d22b81d149f2
Successfully tagged development_web:latest
์ปจํ ์ธ ๊ฐ ์ถ๊ฐ๋์ง ์์๋์ง ํ์ธํ์ญ์์ค.
docker run --rm development_web:latest
/foobar/
โโโ .dockerignore
โโโ Dockerfile
โโโ docker
โโโ development
โโโ docker-compose.yml
2 directories, 3 files
์ด์ .dockerignore
์ด๋ฆ์ ๋ฐ๊พธ๊ณ ๋น๋๋ฅผ ๋ค์ ์ํํ์ญ์์ค.
mv ../../.dockerignore ../../.dockerignore.disabled
docker-compose build --no-cache
Building web
Step 1/4 : FROM alpine
....
์ฝํ ์ธ ๊ฐ ๋ ์ด์ ๋ฌด์๋์ง ์๊ณ ์ด๋ฏธ์ง์ ์ถ๊ฐ๋์๋์ง ํ์ธํฉ๋๋ค.
docker run --rm development_web:latest
/foobar/
โโโ .dockerignore.disabled
โโโ .git
โย ย โโโ this-is-a-git-repo
โโโ Dockerfile
โโโ README.md
โโโ docker
โโโ development
โโโ docker-compose.yml
4 directories, 4 files
(ํธ์ง : ์ฒ์์ผ๋ก -a
tree
๋ฅผ ์คํํ๋ ๊ฒ์ ์์์ผ๋ฏ๋ก ์ฒซ ์คํ์ ์
๋ฐ์ดํธ ๋ ์ถ๋ ฅ)
@thaJeztah ์๊ฐ์๋ด์ด
๋ด ์ฌ์ฉ ์ฌ๋ก๋ https://github.com/docker/compose/issues/2098#issue -108463351์ ์ค๋ช
๋ ๊ฒ๊ณผ ์ ์ฌํฉ๋๋ค. Dockerfile์์ COPY
๋ช
๋ น์ ์ฌ์ฉํ๊ณ ์ถ๊ฐ๋ก ๋ณผ๋ฅจ ๊ณผ ๋์ผํ ๋๋ ํ ๋ฆฌ๋ฅผ ๋ง์ดํธํฉ๋๋ค.
https://github.com/docker/compose/issues/2098#issuecomment -143505943์ ์ค๋ช
๋๋๋ก .dockerignore
์ ์ ์ธ ํญ๋ชฉ์ด ๋ณผ๋ฅจ์ ์ ์ฉ๋ ๊ฒ์ผ๋ก ์์ํ์ต๋๋ค.
# 2098 (์ฃผ์)์ ์ค๋ช ๋๋๋ก .dockerignore์ ์ ์ธ๊ฐ ๋ณผ๋ฅจ์ ์ ์ฉ๋ ๊ฒ์ผ๋ก ์์ํ์ต๋๋ค.
์๋์, ํธ์คํธ์์ ๊ฒฝ๋ก๋ฅผ ๋ฐ์ธ๋ ๋ง์ดํธ ํ ๋ ๋์ปค๋ ๊ทธ "์ค๊ฐ"์ ์์ง ์์ต๋๋ค. Linux์์๋ ๋ง ๊ทธ๋๋ก ์ปจํ ์ด๋ ๋ด๋ถ์ ํธ์คํธ์์ ํด๋น ๋๋ ํ ๋ฆฌ๋ฅผ ๋ง์ดํธํฉ๋๋ค. Docker Desktop (Mac / Windows ์ฉ Docker)์๋ ๋ฐ๋ชฌ (๋ฐ ์ปจํ ์ด๋)์ด ์คํ๋๋ VM ๋ด์์ ํด๋น ํ์ผ์ ์ฌ์ฉํ ์ ์๋๋กํ๋ ๋ช ๊ฐ์ง ์ถ๊ฐ "๋ง๋ฒ"์ด ์์ง๋ง ๊ทธ ์ดํ์๋ Linux์์์ ๋์ผํ๊ฒ ์ํ๋ฉ๋๋ค.
.dockerignore
๋ ๋น๋ ์ค์ ๋ง ์ฌ์ฉ๋๋ฉฐ ๋น๋ ์๋๋ฅผ ๋์ด๊ธฐ์ํ ๊ฒ์
๋๋ค. ์ด๋ฏธ์ง์์ ์ฌ์ฉ / ์ํ์ง ์๋ ํ์ผ์ ๋ฐ๋ชฌ์ผ๋ก ๋ณด๋ด์ง ์์๋๋ฉ๋๋ค.
์ค๋ช
ํด ์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค! ์ด ์ค๋ช
์ ์ปค๋ฎค๋ํฐ์์ ๋ ์ด์์ ์คํด๋ฅผ ํผํ๊ธฐ ์ํด ๋ฌธ์์ ์์ด์ผํ๋ค๊ณ ์๊ฐํฉ๋๋ค. ํ์ฌ ๋ฌธ์ ๋ .dockerignore
์์ฒด์ ๋ฒ์๋ณด๋ค๋ ํ์ผ์ ๋ฌด์ํ๋ ๋ฐฉ๋ฒ์ ๋ ์ค์ ์ ๋ก๋๋ค.
๋ฌธ์์ ํด๋น ํ์ด์ง๋ Dockerfile ๋ฐ docker build
๋ํด ์ค๋ช
ํฉ๋๋ค. ๊ทธ ๊ด์ ์์; ๋ค๋ฅธ ๋ช
๋ น / ์ฉ๋์์๋ ์๋ํ์ง ์๋๋ค๊ณ ์ค๋ช
ํ๋ ๊ฒ์ด ํฉ๋ฆฌ์ ์ผ์ง ๊ถ๊ธํฉ๋๋ค.
๊ธ์, ๊ทธ๊ฒ์ด ์คํด์ ์ผ๋ฐ์ ์ธ ์์ธ์ด๊ณ ๋ถ๋ช ํ ๊ทธ๋ ๋ค๋ฉด ๊ฑฐ๊ธฐ์ ์ธ๊ธํ๋ ๊ฒ์ด ๋ถ๋ช ํฉ๋ฆฌ์ ์ ๋๋ค.
๋ฌธ์์ ํ ๋ฌธ์ฅ ์ผ๋ก @thaJeztah ์ ์๋์ ๋ชจ๋ ์ฌ์ฉ์ ๊ฐ ๋ง์ ์๊ฐ์ ์ ์ฝ ํ ์์์์ต๋๋ค .
ํ์ฌ ๋ฌธ์๋ฅผ ์คํดํ๋ ์ฌ์ฉ์
์ด ๋ฌธ์ ๋ฅผ +1ํ๊ณ ์ถ์์ต๋๋ค.
Docker-copose : 1.23.2๋ฅผ ์คํ ์ค์
๋๋ค (Homebrew์ PIP ์ฌ์ด์์ ์ฐพ์ ์์๋ ๊ฐ์ฅ ์ต๊ทผ)
์ด์์ฒด์ : Mac OS 10.14.2
๋น๋ํ๋ ๋์ ์ฌ์ ํ ๋ด .dockerfile์ ๋ฌด์ํ๊ณ ์์ต๋๋ค. ๊ทธ๋์ ๋ช ์ ์ ์ผ๋ก ๋ณต์ฌํด์ผ ํ ๊ฒ์ ๋๋ค.
docker-compose ํ์ผ์์ ๋ถํ์ํ ๋ณผ๋ฅจ ์ฐธ์กฐ๋ฅผ ์ ๊ฑฐํ์ฌ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๋ค. Compose๋ ๋ณผ๋ฅจ์ ๋ํด .gitignore๋ฅผ ๋ฌด์ํฉ๋๋ค.
์ด๊ฒ์ ๋๋ฅผ ์ํด ์์ ๋์์ต๋๋ค. docker-compose๋ ๋ง์ดํธ ๋ ๋ณผ๋ฅจ์ .dockerignore ํ์ผ์ ๋ฌด์ํฉ๋๋ค.
@xvrqt ๋ด ๊ตฌ์ฑ ํ์ผ์ด ์ ๋๋ก ๋ณต์ฌ๋์ง ์๊ณ ์์์ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ฌ ์ง๋ ์ฃผ์ ๋ช ์๊ฐ์ ๋ญ๋นํ์ ๊ฒ์ ๋๋ค (๋ด ๋น๋ ํ๋ก์ธ์ค๋ ๋ณต์ฌํด์ผํ์ง๋ง ์ฌ์ฉ๋์ง ์๋ .dockerignore ํ์ผ์ ์ํด ์ฐจ๋จ๋์์ต๋๋ค). ์ด๊ฒ์ ๋ฏฟ๊ธฐ์ง ์์ต๋๋ค.
๊ฐ์กฐํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.
์๋
ํ์ธ์! ์ด๊ฒ์ ์ํ๋ ๋ฌด์์
๋๊น? ๋ณผ๋ฅจ์ ํฌํจํ์ง ์๋ ๋งค์ฐ ๊ฐ๋จํ docker-compose.yml ์๋๋ฆฌ์ค๋ฅผ ์ค๋นํ์ง๋ง ์๊ฒฉ git repo์์ ๋น๋ ํ ๋ .dockerignore
์ ์ ํํ์ง ๋ชปํ์ต๋๋ค.
https://github.com/LocoDelAssembly/docker-compose-dockerignore
๋ง์คํฐ ๋ธ๋์น์์ ๋ฐ์ํ๋ ์ค๋ฅ๊ฐ ์์๋ฉ๋๊น? ๋ฐ๋๋ผ ๋์ปค๋ก ์ด๋ฏธ์ง๋ฅผ ๋น๋ํ๊ณ ํ๊ทธ๋ฅผ ์ง์ ํ ๋ค์ docker-compose.yml์์ ์ฌ์ฉํ๋ ๊ฒ ์ธ์ ๋ค๋ฅธ ์๋ฃจ์ ์ด ์์ต๋๊น?
๊ฐ์ฌ
๋ฐ๋๋ผ ๋์ปค๋ก ์ด๋ฏธ์ง๋ฅผ ๋น๋ํ๊ณ ํ๊ทธ๋ฅผ ์ง์ ํ ๋ค์ docker-compose.yml์์ ์ฌ์ฉํ๋ ๊ฒ ์ธ์ ๋ค๋ฅธ ์๋ฃจ์ ์ด ์์ต๋๊น?
ํ์ฌ ๋ฒ์ ์ compose๋ฅผ ์คํ์ค์ธ ๊ฒฝ์ฐ COMPOSE_DOCKER_CLI_BUILD=1
(๋ฐ DOCKER_BUILDKIT=1
) ์ต์
์ ์ฌ์ฉํ์ฌ docker compose๊ฐ ๊ธฐ๋ณธ docker build
์ฌ์ฉํ๋๋ก ํ ์ ์์ต๋๋ค.
๊ทํ์ ์๋ ์ฌ๊ธฐ์์ ๋ ผ์๋๋ ๊ฒ๊ณผ ๋ค๋ฅธ ๊ฒ์ผ๋ก ๋ณด์ด๋ฏ๋ก ์ ํฐ์ผ์ ์ฌ๋ ๊ฒ์ด ์ข์ต๋๋ค (์์ง ํด๋น ํฐ์ผ์ด์๋ ๊ฒฝ์ฐ).
๊ฐ์ฌํฉ๋๋ค @thaJeztah! COMPOSE_DOCKER_CLI_BUILD=1
์ ํจ๊ป ์๋ํ์ง๋ง DOCKER_BUILDKIT=1
๋ ์ถ๊ฐํ๋ฉด ์คํจํฉ๋๋ค (๊ด๋ จ์๋ ์ด์ ๋ก).
https://travis-ci.org/LocoDelAssembly/docker-compose-dockerignore/builds/658351109
ํ , ๊ฑฐ๊ธฐ์์ ์คํ๋๋ ๋์ปค ๋ฒ์ ์ ๋ฒ๊ทธ๋ผ๊ณ ์๊ฐํฉ๋๋ค. docker 18.06์ ๊ฝค ์ค๋๋์์ต๋๋ค (๊ทธ๋ฆฌ๊ณ EOL). ํด๋น ๋ฒ์ ์ ๋์ปค์๋ ์์ง ์์ ์ ์ด์ง ์์ BuildKit์ ์ด๊ธฐ ๋ฒ์ ์ด ์์ต๋๋ค.
```
=> ERROR [๋ด๋ถ] docker.io/library/alpine:3.9.5 0.1s์ ๋ํ ๋ฉํ ๋ฐ์ดํฐ๋ก๋
218 => ์ค๋ฅ [1/5] docker.io/library/alpine:3.9.5 0.0s
219 => => docker.io/library/alpine:3.9.5 0.0s ํด๊ฒฐ
220 ------
221> [๋ด๋ถ] docker.io/library/alpine:3.9.5์ ๋ํ ๋ฉํ ๋ฐ์ดํฐ๋ก๋ :
222 ------
223 ------
224> [1/5] FROM docker.io/library/ alpine : 3.9.5 :
225 ------
226 ํ๋ฐํธ ์๋๋ก ํด๊ฒฐํ์ง ๋ชปํ์ต๋๋ค. dockerfile.v0 : LLB๋ฅผ ๋น๋ํ์ง ๋ชปํ์ต๋๋ค. ์บ์ ํค๋ฅผ๋ก๋ํ์ง ๋ชปํ์ต๋๋ค. docker.io/library/ alpine : 3.9.5 ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.
์ค, ํ , ๋น์ ์ ํธ๋๋น์ค๋ ๋์ปค๋ฅผ ์ค์นํ๊ณ ์๋ ๊ฑธ ๋ด
๋๋ค. ์ฌ์ ์ค์น๋ ๋ฒ์ ์ ๋์ฒดํฉ๋๊น? ์ค์น ํ docker info
๋ฐ docker version
๋จ๊ณ๋ฅผ ์ถ๊ฐํ๋ฉด ์ค์นํ ์ฌ๋ฐ๋ฅธ (19.03.x) ๋ฒ์ ์ docker๊ฐ ํ์๋ฉ๋๊น?
์ฌ๊ธฐ๋ https://travis-ci.org/LocoDelAssembly/docker-compose-dockerignore/builds/658435194์ ๋๋ค.
$ docker version
Client: Docker Engine - Community
Version: 19.03.7
API version: 1.40
Go version: go1.12.17
Git commit: 7141c199a2
Built: Wed Mar 4 01:22:36 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.7
API version: 1.40 (minimum version 1.12)
Go version: go1.12.17
Git commit: 7141c199a2
Built: Wed Mar 4 01:21:08 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
docker info
์ถ๋ ฅ์ ์ฝ๊ฐ ํฌ๋ฏ๋ก ํฌํจ๋์ง ์์ง๋ง Server Version: 19.03.7
.
$ docker-compose version
docker-compose version 1.26.0-rc1, build 07cab513
docker-py version: 4.2.0
CPython version: 3.7.6
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
(๋ณด๊ณ ๋ ๋ฒ์ ์ด ์๋ชป๋จ, rc2, ๋น๋ ํด์๊ฐ rc2์ ์ผ์น ํจ)
$ docker-compose version
docker-compose version 1.25.4, build 8d51620a
docker-py version: 4.1.0
CPython version: 3.7.5
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
19.03.8์์ ์ฌ์ ํ ๋ฌธ์ ๊ฐ ์กด์ฌํฉ๋๋ค.
19.03.8์์ ์ฌ์ ํ ๋ฌธ์ ๊ฐ ์กด์ฌํฉ๋๋ค.
์ณ์. ๋ํ ๋ด ํ ์คํธ ์ ์ฅ์๋ฅผ ์ต์ 1.25 ๋ฐ 1.26 docker-compose ๋ฒ์ ์ผ๋ก ์ ๋ฐ์ดํธํ์ง๋ง ๋ชจ๋ https://github.com/LocoDelAssembly/docker-compose-dockerignore์ ์ค๋ช ๋๋๋ก ๊ณ์ ์ ์ง๋ฉ๋๋ค.
์์์ ๋ถ์ฌ ๋ฃ์ ๋์ผํ ์ข ๋ฅ์ ์ ๋ณด๋ฅผ ์ฐพ์ ์์๋ ๋น๋ : https://travis-ci.org/github/LocoDelAssembly/docker-compose-dockerignore/builds/673393656
์ฌ๊ธฐ์ ๋์ผํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. .dockerignore
๋ docker-compose
์์ ์์ ์ ์ผ๋ก ์๋ํ์ง ์์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
.dockerignore๊ฐ
docker build -t subdir ../
์์๋ ์๋ํ์ง๋งdocker-compose build
์์๋ ์๋ํ์ง ์๋ ์ด์ ๋ ๋ฌด์์ ๋๊น?