I’m setting up my development environment and this time around I am using a docker container to run everything… like tmux, vim, etc.
When I run the image that runs my editor I use
-v /var/run/docker.sock:/var/run/docker.sock and that way when I use the
docker command in the shell of the editor container it links to docker on the host computer and I can run additional docker containers without an issue. This way I can code in my editor container and spin up other containers as dev envs.
However, if I try to run the same Dockerfile from the editor container that worked using
docker build and
docker run using a docker-compose.yml and
docker-compose up I get the following output:
Recreating frontend_tests_1 ... done Recreating frontend_web_1 ... done Attaching to frontend_tests_1, frontend_web_1 tests_1 | npm ERR! path /app/package.json tests_1 | npm ERR! code ENOENT tests_1 | npm ERR! errno -2 tests_1 | npm ERR! syscall open web_1 | npm ERR! path /app/package.json web_1 | npm ERR! code ENOENT web_1 | npm ERR! errno -2 web_1 | npm ERR! syscall open tests_1 | npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json' tests_1 | npm ERR! enoent This is related to npm not being able to find a file. tests_1 | npm ERR! enoent web_1 | npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json' web_1 | npm ERR! enoent This is related to npm not being able to find a file. web_1 | npm ERR! enoent tests_1 | tests_1 | npm ERR! A complete log of this run can be found in: tests_1 | npm ERR! /root/.npm/_logs/2019-03-24T22_08_49_446Z-debug.log web_1 | web_1 | npm ERR! A complete log of this run can be found in: web_1 | npm ERR! /root/.npm/_logs/2019-03-24T22_08_49_447Z-debug.log frontend_web_1 exited with code 254 frontend_tests_1 exited with code 254
If I preform the same steps on the host machine using the same directory, I get the following normal output:
Recreating frontend_web_1 ... done Recreating frontend_tests_1 ... done Attaching to frontend_web_1, frontend_tests_1 web_1 | web_1 | > [email protected] start /app web_1 | > react-scripts start web_1 | tests_1 | tests_1 | > [email protected] test /app tests_1 | > react-scripts test --env=jsdom tests_1 | web_1 | Starting the development server... web_1 | tests_1 | PASS src/App.test.js tests_1 | ✓ renders without crashing (22ms) tests_1 | tests_1 | Test Suites: 1 passed, 1 total tests_1 | Tests: 1 passed, 1 total tests_1 | Snapshots: 0 total tests_1 | Time: 1.352s tests_1 | Ran all test suites related to changed files. tests_1 | tests_1 | Watch Usage tests_1 | › Press p to filter by a filename regex pattern. tests_1 | › Press t to filter by a test name regex pattern. tests_1 | › Press q to quit watch mode. tests_1 | › Press Enter to trigger a test run. web_1 | Compiled successfully! web_1 | web_1 | You can now view frontend in the browser. web_1 | web_1 | Local: http://localhost:3000/ web_1 | On Your Network: http://0.0.0.0:3000/ web_1 | web_1 | Note that the development build is not optimized. web_1 | To create a production build, use yarn build. web_1 | ^CGracefully stopping... (press Ctrl+C again to force) Stopping frontend_tests_1 ... done Stopping frontend_web_1 ... done
FROM node:alpine WORKDIR '/app' COPY package.json . RUN npm install COPY ./ ./ CMD ["npm", "run", "start"]
version: '3' services: web: build: context: . dockerfile: Dockerfile.dev ports: - "8080:8080" volumes: - /app/node_modules - .:/app tests: build: context: . dockerfile: Dockerfile.dev volumes: - /app/node_modules - .:/app command: ["npm", "run", "test"]