How to add Vue to existing Laravel Docker app - docker

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

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?

Adonis js with docker /app/server.js error

I´ve been looking all over to find a solution to this, and i have the feeling it´s something small i´m missing but i just can´t get this working. I started with a adonis js v.5 app and then i want to dockerize it, but it keeps giving me the error below when i do docker-compose up --build:
lwdis-api | Error: Cannot find module '/app/server.js'
lwdis-api | at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
lwdis-api | at Function.Module._load (node:internal/modules/cjs/loader:778:27)
lwdis-api | at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
lwdis-api | at node:internal/main/run_main_module:17:47 {
lwdis-api | code: 'MODULE_NOT_FOUND',
lwdis-api | requireStack: []
lwdis-api | }
lwdis-api |
lwdis-api | Node.js v17.5.0
Dockerfile:
FROM node
WORKDIR /app
COPY package.json /app
RUN npm i -g #adonisjs/cli && npm install
COPY . .
EXPOSE 3333
CMD ["npm", "start"]
docker-compose.yml:
version: "3"
services:
lwdis_db:
image: mysql:5.7
ports:
- "33101:3306"
volumes:
- $PWD/data:/var/lib/mysql
environment:
MYSQL_USER: ${MYSQL_USER}
MYSQL_DATABASE: ${MYSQL_DB_NAME}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_ROOT_PASSWORD: ${MYSQL_PASSWORD}
networks:
- api-network
lwdis_api:
container_name: "${APP_NAME}-api"
build: .
environment:
- HOST=0.0.0.0
volumes:
- .:/app
ports:
- "3333:3333"
depends_on:
- lwdis_db
networks:
- api-network
networks:
api-network:
I started with this package, and the problem was right at the begining, when i do the docker ps it shows the mysql container but not the api container, which i think it will be a problem since i have or want to add another modules etc. Then i deleted all containers and images related to it and this time i use the docker-compose up --build which shows me this error. I don´t have a server.js file but i have a server.ts file at the root of the app.
I was hopping someone could help me with this. Thanks in advance.
Try with this:
API Dockerfile
FROM node:12.18.2-alpine3.9
RUN mkdir /srv/app && chown node:node /srv/app
RUN npm install -g #adonisjs/cli
USER node
WORKDIR /srv/app
COPY --chown=node:node package.json package-lock.json ./
RUN npm install --quiet
# TODO: Can remove once we have some dependencies in package.json.
RUN mkdir -p node_modules
COPY . .
RUN cp .env.example .env
#to run node.js script with sudo as we want to listen on port 80
USER root
EXPOSE 80
CMD ["npm","start"]
Mysql dockerfile
FROM mariadb:10.4
docker-compose
version: '3'
services:
db:
container_name: "${SERVICE_PREFIX}-db"
build:
context: ../.
dockerfile: ./docker/mariadb/Dockerfile
env_file:
- ../.env
ports:
- "127.0.0.1:3306:3306"
volumes:
- ${DB_VOLUME_PATH}:/var/lib/mariadb
environment:
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
MYSQL_DATABASE: "${DB_DATABASE}"
MYSQL_USER: "${DB_USER}"
MYSQL_PASSWORD: "${DB_PASSWORD}"
networks:
- api-network
restart: always
api:
container_name: "${SERVICE_PREFIX}-api"
tty: true
build:
context: ../.
dockerfile: ./docker/api/Dockerfile
volumes:
- ../.:/srv/app
- app_node_modules:/srv/app/node_modules
restart: always
env_file:
- ../.env
environment:
- HOST=0.0.0.0 # listen on all interfaces
- SERVER_ENV=development
ports:
- "${PORT}:80" # matches actual listener message
depends_on:
- db
networks:
- api-network
networks:
api-network:
driver: "bridge"
volumes:
mysqldata:
driver: "local"
app_node_modules:

Docker file update volume

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:

docker port mapping using docker-gen and letsencrypt-companion

i have several flask applications which i want to run on a server as separate docker containers. on the server i already have several websites running with a reverse proxy and the letsencrypt-nginx-proxy-companion. unfortunately i can't get the containers to run. I think it is because of the port mapping. When I start the containers on port 80, I get the following error message "[ERROR] Can't connect to ('', 80)" from gunicorn. On all other ports it starts successfully, but then I can't access it from outside.
what am I doing wrong?
docker-compose.yml
version: '3'
services:
db:
image: "mysql/mysql-server:5.7"
env_file: .env-mysql
restart: always
app:
build: .
env_file: .env
expose:
- "8001"
environment:
- VIRTUAL_HOST:example.com
- VIRTUAL_PORT:'8001'
- LETSENCRYPT_HOST:example.com
- LETSENCRYPT_EMAIL:foo#example.com
links:
- db:dbserver
restart: always
networks:
default:
external:
name: nginx-proxy
Dockerfile
FROM python:3.6-alpine
ARG CONTAINER_USER='flask-user'
ENV FLASK_APP run.py
ENV FLASK_CONFIG docker
RUN adduser -D ${CONTAINER_USER}
USER ${CONTAINER_USER}
WORKDIR /home/${CONTAINER_USER}
COPY requirements requirements
RUN python -m venv venv
RUN venv/bin/pip install -r requirements/docker.txt
COPY app app
COPY migrations migrations
COPY run.py config.py entrypoint.sh ./
# runtime configuration
EXPOSE 8001
ENTRYPOINT ["./entrypoint.sh"]
entrypoint.sh
#!/bin/sh
source venv/bin/activate
flask deploy
exec gunicorn -b :8001 --access-logfile - --error-logfile - run:app
reverse-proxy/docker-compose.yml
version: '3'
services:
nginx:
image: nginx
labels:
com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: "true"
container_name: nginx
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- /srv/www/nginx-proxy/conf.d:/etc/nginx/conf.d
- /srv/www/nginx-proxy/vhost.d:/etc/nginx/vhost.d
- /srv/www/nginx-proxy/html:/usr/share/nginx/html
- /srv/www/nginx-proxy/certs:/etc/nginx/certs:ro
nginx-gen:
image: jwilder/docker-gen
command: -notify-sighup nginx -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
container_name: nginx-gen
restart: always
volumes:
- /srv/www/nginx-proxy/conf.d:/etc/nginx/conf.d
- /srv/www/nginx-proxy/vhost.d:/etc/nginx/vhost.d
- /srv/www/nginx-proxy/html:/usr/share/nginx/html
- /srv/www/nginx-proxy/certs:/etc/nginx/certs:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
- /srv/www/nginx-proxy/nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro
nginx-letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: nginx-letsencrypt
restart: always
volumes:
- /srv/www/nginx-proxy/conf.d:/etc/nginx/conf.d
- /srv/www/nginx-proxy/vhost.d:/etc/nginx/vhost.d
- /srv/www/nginx-proxy/html:/usr/share/nginx/html
- /srv/www/nginx-proxy/certs:/etc/nginx/certs:rw
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
NGINX_DOCKER_GEN_CONTAINER: "nginx-gen"
NGINX_PROXY_CONTAINER: "nginx"
DEBUG: "true"
networks:
default:
external:
name: nginx-proxy

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"]

Resources