docker composeで「Error response from daemon: driver failed programming external connectivity on endpoint ねーむ (はっしゅ): Bind for 0.0.0.0:3000 failed: port is already allocated」がでてハマりかけたエラーについて
結論(どうすればよいか)
service node-app:の
ports:
- "3000:3000"
をdocker-compose.yml
から消せ
恐らくdocker compose up -d した際にdocker-compose.ymlで指定したポートとnginxのポートで重複が起きていると思われる
# 直したもの
#/home/ubuntu/work/study/node-docker/docker-compose.yml
version: "3.0"
services:
nginx:
image: nginx:stable-alpine
ports:
- "3000:80"
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
node-app:
build: .
environment:
- PORT=3000
depends_on:
- mongo
mongo:
image: mongo
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=admin
volumes:
- mongo-db:/data/db
redis:
image: redis
volumes:
mongo-db:
# 試していたこと
sudo service docker restart
docker ps -a
docker image prune #以外と効く
docker volume prune #以外と効く
docker compose down系
docker compose up系
エラー内容
Error response from daemon: driver failed programming external connectivity on endpoint node-docker-node-app-1 (a0bdddba46ccc936a01797c9d804da64859594dd829f593f5dbd5d771ff34d00): Bind for 0.0.0.0:3000 failed: port is already allocated
ソース
※もう直しているので再現はしません
github
https://github.com/2f0833e717/node-docker
実際のコンソール出力内容
ubuntu@DESKTOP-GF7U2U8:~/work/study/node-docker$ docker compose -f docker-compose.yml -f docker-compose.dev.yml down
[+] Running 1/0
⠿ node-docker Warning: No resource found to remove 0.0s
ubuntu@DESKTOP-GF7U2U8:~/work/study/node-docker$ docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --build
[+] Building 0.2s (10/10) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/library/node:15 0.0s
=> [1/5] FROM docker.io/library/node:15 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 815B 0.0s
=> CACHED [2/5] WORKDIR /app 0.0s
=> CACHED [3/5] COPY package.json . 0.0s
=> CACHED [4/5] RUN if [ "development" = "development" ]; then npm install; else npm install --only=production; fi 0.0s
=> CACHED [5/5] COPY . ./ 0.0s
=> exporting to image 0.1s
=> => exporting layers 0.0s
=> => writing image sha256:1ae62b5b7c9b02006e672e29d198d3cd3431b5cff83cb0ad4f8d911370c63dc0 0.0s
=> => naming to docker.io/library/node-docker_node-app 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
[+] Running 5/6
⠿ Network node-docker_default Created 0.0s
⠿ Volume "node-docker_mongo-db" Created 0.0s
⠿ Container node-docker-redis-1 Started 0.9s
⠿ Container node-docker-mongo-1 Started 1.2s
⠿ Container node-docker-nginx-1 Started 1.2s
⠿ Container node-docker-node-app-1 Starting 1.3s
Error response from daemon: driver failed programming external connectivity on endpoint node-docker-node-app-1 (a0bdddba46ccc936a01797c9d804da64859594dd829f593f5dbd5d771ff34d00): Bind for 0.0.0.0:3000 failed: port is already allocated
余談その1 写経の元ネタ
[Youtube] [Google自動翻訳]
Dockerを学ぶ-Node.jsとExpressを使用したDevOps
エラー対応 参考:
今回はぎり一発?(違和感はミリかすったが気が付かなかったので反省点としてはちゃんと理解してググる必要があった)