Docker file update volume - docker

Hello I have a project in elixir, but I have doubts about how I can make a link whenever I update my files locally update the docker,
so you don't have to use docker-compose up every time something is updated.
my docker file :
FROM elixir:alpine
RUN apk add --update --no-cache curl py-pip
RUN apk add --no-cache build-base git
WORKDIR /app
RUN mix local.hex --force && \
mix local.rebar --force
COPY mix.exs mix.lock ./
COPY config config
RUN mix do deps.get, deps.compile
COPY priv priv
COPY lib lib
COPY numbers.csv numbers.csv
COPY docker-entrypoint.sh docker-entrypoint.sh
EXPOSE 4000
docker-compose:
version: "3.7"
services:
app:
restart: on-failure
build: .
command: /bin/sh docker-entrypoint.sh
ports:
- "4000:4000"
depends_on:
- postgres-db
links:
- postgres-db
env_file:
- .env
postgres-db:
image: "postgres:12"
restart: always
container_name: "postgres-db"
environment:
POSTGRES_PASSWORD: ${DB_PASS}
POSTGRES_USER: ${DB_USER}
POSTGRES_DB: ${DB_NAME}
ports:
- "5432:5432"
folder structure:

You should have another docker-compose file called docker-compose.override.yml which is your setup for local development. In that file, you can use volumes to get local file updates being reflected in the docker container (while it's running):
It will look something like this (look at the volumes part):
version: "3.8"
services:
db:
image: postgres:13.0
env_file:
- ./docker/dev.env
restart: always
ports:
- "5432:5432"
volumes:
- db-data:/var/lib/postgresql/data
spiritpay:
image: spiritpay:local
build:
context: .
dockerfile: ./Dockerfile
depends_on:
- db
stdin_open: true
tty: true
env_file:
- ./docker/dev.env
ports:
- "4000:4000"
- "4002:4002"
volumes:
- /opt/spiritpay/assets/node_modules
- ./assets:/opt/spiritpay/assets
- ./config:/opt/spiritpay/config:ro
- ./lib:/opt/spiritpay/lib:ro
- ./priv:/opt/spiritpay/priv
- ./test:/opt/spiritpay/test:ro
- ./mix.exs:/opt/spiritpay/mix.exs:ro
- ./mix.lock:/opt/spiritpay/mix.lock:ro
volumes:
db-data:

Related

nest.js development with docker-compose not adding host node_modules in WebStorm

I am trying to create a Nest.js + PostgreSQL with Prisma ORM Docker development environment for an existing project. I am using Docker Desktop app. Here is my Dockerfile:
FROM node:16.15-alpine3.15 AS builder
# Create app directory
WORKDIR /app
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
COPY prisma ./prisma/
# Install app dependencies
RUN npm install
RUN npm install --only=dev
COPY . .
RUN npm run build
EXPOSE 3000
CMD [ "npm", "run", "start:dev" ]
And Here is my docker-compose.yaml:
version: "3.8"
services:
db:
image: postgres
container_name: local_pgdb
restart: always
expose:
- "5432"
ports:
- "54321:5432"
volumes:
- "pg_data:/var/lib/postgresql"
- "pg_log:/var/log/postgresql"
- "pg_config:/etc/postgresql"
- ./docker-config/db:/docker-entrypoint-initdb.d/
env_file:
- ./docker-config/db/postgres.env
pgadmin:
image: dpage/pgadmin4
container_name: pgadmin4_container
restart: always
expose:
- "80"
ports:
- "5050:80"
volumes:
- pgadmin_data:/var/lib/pgadmin
env_file:
- ./docker-config/pgadmin/pgadmin.env
depends_on:
- db
contents_api:
build:
context: ./
dockerfile: Dockerfile.local
container_name: jccme-dp-contents-api
expose:
- "3000"
ports:
- "3000:3000"
volumes:
- ./:/app
- storage:/app/storage
stdin_open: true
tty: true
depends_on:
- db
volumes:
pg_data:
driver: local
pg_log:
driver: local
pg_config:
driver: local
pgadmin_data:
driver: local
storage:
driver: local
Now when I try docker-compose up, then the node_modules folder and dist folder becomes empty. As a result I get a lot of errors of "module not found". Also eslint service cannot start because of empty node_modules folder.
I have tried both VSCode and WebStorm and both gave errors.
Can anyone tell me what am I doing wrong?

How to add Vue to existing Laravel Docker app

I have a simple, working Laravel app which uses Docker and I am trying to add Vue.
Here is my docker-compose.yml:
version: '3.1'
services:
### THIS IS WHAT I ADDED
# Frontend service
frontend:
image: node:current-alpine
build: ./sandbox
container_name: my_app_frontend
ports:
- 8080:8080
volumes:
- "/app/node_modules"
- ".:/app"
command: "npm run serve"
###
#PHP Service
my_app:
build:
context: .
dockerfile: 'Dockerfile'
image: digitalocean.com/php
container_name: my_app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#NPM Service
my_app_npm:
image: node:latest
container_name: my_app_npm
volumes:
- ./:/var/www/
working_dir: /var/www/
tty: true
networks:
- app-network
#Nginx Service
my_app_server:
image: nginx:alpine
container_name: my_app_webserver
restart: unless-stopped
tty: true
ports:
- "82:80"
- "4443:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#MySQL Service
my_app_db:
image: mysql:5.7
command: --default-authentication-plugin=mysql_native_password --innodb-use-native-aio=0
container_name: my_app_db
restart: always
tty: true
ports:
- "8082:3306"
environment:
MYSQL_PASSWORD: xxxxx
MYSQL_ROOT_PASSWORD: xxxxx
volumes:
- ./mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
#Phpmyadmin Service
my_app_phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: my_app_phpmyadmin
restart: always
links:
- my_app_db
depends_on:
- my_app_db
ports:
- 8083:80
environment:
PMA_HOST: my_app_db
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
Here is my Dockerfile in my Vue directory:
FROM node:lts-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
EXPOSE 8080
CMD ["npm", "run", "serve"]
The file structure looks like this:
-app
-database
-mysql
-nginx
-sandbox(vue)
-node_modules
-public
-src
Dockerfile
package.json
...
docker-compose.yml
Dockerfile
package.json
...
docker-compose build //works
docker-compose up //fails with this error
This relative module was not found:
my_app_frontend |
my_app_frontend | * ./src/main.js in multi (webpack)-dev-server/client/index.js (webpack)/hot/dev-server.js ./src/main.js
my_app_frontend | [webpack.Progress] 100%
What am I missing?
Figured it out, here is my updated Dockerfile.
FROM node:lts-alpine
# install simple http server for serving static content
WORKDIR /app
COPY package*.json ./
RUN npm install
# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY . . // THIS WAS MISSING
EXPOSE 8080
CMD ["npm", "run", "serve"]
Those who are using Vue webpack in Laravel and trying to dockerize.
You just need to add these below two lines in your Dockerfile.
FROM node:10-alpine
RUN npm i -g webpack webpack-cli
Reference:
https://hub.docker.com/r/91dave/webpack-cli

Two SIMILAR docker-compose files are not giving the same result

This is my Dockerfile in ./:
FROM cypress/base:10
COPY package.json package.json
# to install all the necessary packages from packages.json
RUN npm i
# copy in the tests, fixtures, plugins and any custom commands
COPY ./cypress ./cypress
COPY ./cypress.json ./cypress.json
RUN $(npm bin)/cypress verify
RUN $(npm bin)/cypress run
This is my docker-compose.yml file in which the tests have no problem in visiting pa-portal:8080
version: '3.8'
services:
pa-portal:
image: company-docker-registry.company.net/project/web_page:latest
container_name: pa-portal
volumes:
- productDB:/project_webpage/db
ports:
- "8080:8080"
cypress:
image: "cypress/included:4.4.0"
depends_on:
- pa-portal
environment:
- CYPRESS_baseUrl=http://pa-portal:8080
working_dir: /cypress-testing
volumes:
- ./:/cypress-testing
volumes:
productDB:
However I realised I needed my own dependencies (and hence why I created my own Dockerfile), but I didn't change anything in the "pa-portal" service, yet my tests say "failed trying to load http://pa-portal:8080", using the following file which I have named docker-compose copy.yml
version: '3.8'
services:
pa-portal:
image: company-docker-registry.company.net/project/web_page:latest
container_name: pa-portal
volumes:
- productDB:/project_webpage/db
ports:
- "8080:8080"
cypress:
build: ./
depends_on:
- pa-portal
volumes:
- productDB:/db
volumes:
productDB:

Live debugging node application running in docker

I have application built in React running on Docker. I am looking for a way to debug it. I am using Visual Studio Code. Here is my Docker file and Docker-compose file
FROM node:boron
ARG build_env
RUN mkdir /usr/share/unicode && cd /usr/share/unicode && wget ftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt
COPY package.json /tmp/package.json
RUN cd /tmp && npm install
COPY ./shim/RelayDefaultNetworkLayer.js /tmp/node_modules/react-relay/lib/RelayDefaultNetworkLayer.js
COPY ./shim/buildRQL.js /tmp/node_modules/react-relay/lib/buildRQL.js
RUN mkdir -p /var/www && cp -a /tmp/node_modules /var/www/
WORKDIR /var/www
COPY . ./
RUN if [ "$build_env" != "development" ]; then npm run build-webpack && npm run gulp; fi
EXPOSE 8080
CMD ["npm", "run", "--debug=5858 prod"]
My docker-compose file looks like
version: '2'
services:
nginx:
container_name: nginx
image: openroad/nginx
build:
context: nginx
ports:
- "80:80"
volumes:
- ./nginx/nginx.development.conf:/etc/nginx/nginx.conf
networks:
- orion-network
graphql:
container_name: graphql
image: openroad/graphql
build:
context: integration_api
volumes:
- ./integration_api:/var/www
environment:
- NODE_ENV=development
command: npm run dev
working_dir: /var/www
networks:
orion-network:
ipv4_address: 172.16.238.10
pegasus:
container_name: pegasus
image: openroad/pegasus
build:
context: pegasus
args:
build_env: development
expose:
- "3000"
volumes:
- ./pegasus:/var/www/public
environment:
- NODE_ENV=development
command: npm run dev
working_dir: /var/www/public
extra_hosts:
- "local.pegasus.com:192.168.99.100"
networks:
orion-network:
ipv4_address: 172.16.238.11
frontend:
container_name: orion-frontend
image: openroad/orion-frontend
build:
context: orion-frontend
args:
build_env: development
expose:
- "3000"
ports:
- "5858:5858"
volumes:
- ./orion-frontend:/var/www/public
environment:
- NODE_ENV=development
command: npm run --debug=5858 dev
working_dir: /var/www/public
networks:
orion-network:
ipv4_address: 172.16.238.12
admin:
container_name: orion-admin
image: openroad/orion-admin
build:
context: orion-admin
args:
build_env: development
expose:
- "3000"
volumes:
- ./orion-admin:/var/www/
environment:
- NODE_ENV=development
command: npm run dev
working_dir: /var/www/
networks:
orion-network:
ipv4_address: 172.16.238.13
uploads:
container_name: orion-uploads
image: openroad/orion-uploads
build:
context: orion-uploads
volumes:
- ./orion-uploads:/var/www/
working_dir: /var/www/
networks:
orion-network:
ipv4_address: 172.16.238.14
dashboard:
container_name: orion-dashboard
image: openroad/orion-dashboard
build:
context: orion-dashboard
args:
build_env: development
volumes:
- ./orion-dashboard/src:/var/www/src
- ./orion-dashboard/package.json:/var/www/package.json
- ./orion-dashboard/webpack.config.babel.js:/var/www/webpack.config.babel.js
- ./orion-dashboard/node_modules:/var/www/node_modules
- ./orion-dashboard/data/babelRelayPlugin.js:/var/www/data/babelRelayPlugin.js
working_dir: /var/www
environment:
- NODE_ENV=development
- GRAPHQLURL=http://172.16.238.10:8080/graphql
- PORT=8080
command: npm run dev
networks:
orion-network:
ipv4_address: 172.16.238.15
networks:
orion-network:
driver: bridge
driver_opts:
com.docker.network.bridge.enable_ip_masquerade: "true"
ipam:
driver: default
config:
- subnet: 172.16.238.0/24
gateway: 172.16.238.1
I wanted ability to debug application running under orion-frontend container. I tried various option without any success. I tried https://codefresh.io/docker-tutorial/debug_node_in_docker/ and https://blog.docker.com/2016/07/live-debugging-docker/ already.
I may be wrong about the command syntax for npm run (didn't find this command in the npm docs), but you may need to separate the --debug=5858 and prod args, like this:
CMD ["npm", "run", "--debug=5858", "prod"]

Cannot launch django with celery in Docker Compose v3

Here is my docker-compose.yml:
version: '3.4'
services:
nginx:
restart: always
image: nginx:latest
ports:
- 80:80
volumes:
- ./misc/nginx.conf:/etc/nginx/conf.d/default.conf
- /static:/static
depends_on:
- web
web:
restart: always
image: celery-with-docker-compose:latest
build: .
command: bash -c "python /code/manage.py collectstatic --noinput && python /code/manage.py migrate && /code/run_gunicorn.sh"
volumes:
- /static:/data/web/static
- /media:/data/web/media
- .:/code
env_file:
- ./.env
depends_on:
- db
volumes:
- ./app:/deploy/app
worker:
image: celery-with-docker-compose:latest
restart: always
build:
context: .
command: bash -c "pip install -r /code/requirements.txt && /code/run_celery.sh"
volumes:
- .:/code
env_file:
- ./.env
depends_on:
- redis
- web
db:
restart: always
image: postgres
env_file:
- ./.env
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "5432:5432"
redis:
restart: always
image: redis:latest
privileged: true
command: bash -c "sysctl vm.overcommit_memory=1 && redis-server"
ports:
- "6379:6379"
volumes:
pgdata:
When I run docker stack deploy -c docker-compose.yml cryptex I got
Non-string key at top level: true
And docker-compose -f docker-compose.yml config gives me
ERROR: In file './docker-compose.yml', the service name True must be a quoted string, i.e. 'True'.
I'm using latest versions of docker and compose. Also I'm new to compose v3 and started to use it for getting availability of docker stack command. If you see any mistakes or redudants in config file please, let me know. Thanks
you have to validate you docker compose file, is probably that the have low value inside
Validating your file now is as simple as docker-compose -f
docker-compose.yml config. As always, you can omit the -f
docker-compose.yml part when running this in the same folder as the
file itself or having the

Resources