This is the dockerfile:
FROM node
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
EXPOSE 3001
CMD [ "npm","start" ]
this is the docker-compose file:
userPortal:
image: userportal:latest
ports:
- 3001:3001
links:
- apiServer
command: ["npm","start"]
this is the docker-compose ps:
localdeployment_userPortal_1 docker-entrypoint.sh npm start Up 0.0.0.0:3001->3001/tcp
this is the package-json:
"scripts": {
"start": "set PORT=3001 && react-scripts start",
...}
this is the container's logs:
userPortal_1 |
userPortal_1 | > user-portal#0.1.0 start
userPortal_1 | > set PORT=3001 && react-scripts start
userPortal_1 |
userPortal_1 | (node:31) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
userPortal_1 | (Use `node --trace-deprecation ...` to show where the warning was created)
userPortal_1 | (node:31) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
userPortal_1 | Starting the development server...
and this is what I get when I try to access localhost:3001
[1]: https://i.stack.imgur.com/lwaOR.png
When I use npm start without docker it works fine so it is not a proxy problem.
Related
I am trying to run a docker-compose file but there is a error that i can´t solve by myself.
I don´t know how to delete the info in the directory that the error specifies, can anyone help??
My dockerfile content:
FROM python:3
RUN apt-get update -y; apt-get upgrade -y
RUN yes | apt install build-essential portaudio19-dev
RUN python -m pip install --upgrade pip
COPY ./dependecies/requirements.txt .
COPY . ./usr/src/app
WORKDIR /usr/src/app
RUN pip install --upgrade pip
RUN pip install torch
RUN pip install -r requirements.txt
CMD ["python", "main"]
My docker-compose content:
version: '3.9'
services:
python_app:
build: ./facadeback/
container_name: python-backend
volumes:
- ./facadeback:usr/src/app
command: sh -c "sleep 10s"
depends_on:
- mysql_db
mysql_db:
image: mysql
container_name: mysql-bd
restart: always
environment:
MYSQL_ROOT_PASSWORD: 1234
volumes:
- ./facadeadd/bd/:var/lib/mysql
ports:
- '3306:3306'
The error log is this when i try to run docker-compose up:
[+] Running 2/0
- Container mysql-bd Created
- Container python-backend Created
Attaching to mysql-bd, python-backend
mysql-bd | 2022-11-24 10:37:43+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.31-1.el8 started.
mysql-bd | 2022-11-24 10:37:43+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql-bd | 2022-11-24 10:37:43+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.31-1.el8 started.
mysql-bd | 2022-11-24 10:37:43+00:00 [Note] [Entrypoint]: Initializing database files
mysql-bd | 2022-11-24T10:37:43.952783Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
mysql-bd | 2022-11-24T10:37:43.953374Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.31) initializing of server in progress as process 80
mysql-bd | 2022-11-24T10:37:43.956544Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
mysql-bd | 2022-11-24T10:37:43.956550Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
mysql-bd | 2022-11-24T10:37:43.956624Z 0 [ERROR] [MY-010119] [Server] Aborting
mysql-bd | 2022-11-24T10:37:43.956756Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31) MySQL Community Server - GPL.
mysql-bd exited with code 1
I'm trying to build a simple next.js app with Docker compose but it keeps failing on docker-compose build with an exit code 135. I'm running it on a Mac M1 Pro (if that is relevant).
I couldn't find any resources pointing to an exit code 135 though.
This is the docker-compose.yaml
version: '3'
services:
next-app:
image: node:18-alpine
volumes:
- ./:/site
command: >
sh -c "npm install && npm run build && yarn start -H 0.0.0.0 -p 80"
working_dir: /site
ports:
- 80:80
And the logs:
[+] Running 1/0
⠿ Container next-app Created 0.0s
Attaching to next-app
next-app |
next-app | up to date, audited 551 packages in 3s
next-app |
next-app | 114 packages are looking for funding
next-app | run `npm fund` for details
next-app |
next-app | 5 moderate severity vulnerabilities
next-app |
next-app | To address all issues (including breaking changes), run:
next-app | npm audit fix --force
next-app |
next-app | Run `npm audit` for details.
next-app |
next-app | > marketing-site-v2#0.1.0 build
next-app | > next build
next-app |
next-app | info - Linting and checking validity of types...
next-app |
next-app | ./pages/cloud.tsx
next-app | 130:6 Warning: Do not use <img>. Use Image from 'next/image' instead. See: https://nextjs.org/docs/messages/no-img-element #next/next/no-img-element
next-app | 133:6 Warning: Do not use <img>. Use Image from 'next/image' instead. See: https://nextjs.org/docs/messages/no-img-element #next/next/no-img-element
next-app | 150:6 Warning: Do not use <img>. Use Image from 'next/image' instead. See: https://nextjs.org/docs/messages/no-img-element #next/next/no-img-element
next-app |
next-app | ./pages/index.tsx
next-app | 176:10 Warning: Image elements must have an alt prop, either with meaningful text, or an empty string for decorative images. jsx-a11y/alt-text
next-app |
next-app | ./components/main-content-display.tsx
next-app | 129:6 Warning: Do not use <img>. Use Image from 'next/image' instead. See: https://nextjs.org/docs/messages/no-img-element #next/next/no-img-element
next-app |
next-app | info - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
next-app | info - Creating an optimized production build...
next-app | Bus error
next-app exited with code 135
Without knowing exactly what's in your package.json file - I would try this.
Spin up your vanilla node:18-alpine image without installing dependencies via the adjusted compose file below.
version: '3'
services:
next-app:
image: node:18-alpine
container_name: my_test_container
volumes:
- ./:/site
command: >
sh -c "tail -f /dev/null"
working_dir: /site
ports:
- 80:80
The command being used here
sh -c "tail -f /dev/null"
is a popular vanilla option for keeping a container up and running when using compose (and when not executing some other command e.g,. npm start that would keep the container running otherwise).
I have also added a container_name for reference here.
Next, enter the container and try running each command in your original sh sequentially (starting with npm install). See if one of those commands is a problem.
You can enter the container (using the container_name above) via the command below to test
docker container exec -u 0 -it my_test_container bash
As an aside, at some point I would pull commands like npm install from your compose file back to a Dockerfile defining your image (here node:18-alpine) and any additional custom installs you need for your application (here contained in package.json).
You did use sh commend in docker-compose which is not a good practice to use docker.
You need docker-compose.yml along with Dockerfile as mentioned below.
docker-compose.yml
version: "3"
services:
next-app:
build: .
ports:
- "80:80"
in Dockerfile
FROM node:16.15.1-alpine3.16 as site
WORKDIR /usr/src/site
COPY site/ .
RUN npm install
RUN npm run build
EXPOSE 80
CMD npm start
after this changes you just need a single command to start server.
docker-compose up --build -d
I have a small fastify app that connects to an external Redis server.
I am using the fastify-redis npm package (which uses ioredis under the hood).
fastify-redis is connecting using rediss:// format
REDIS_URL='rediss://:xxxxyyyyxxxyxxxyxyxyxyxyxxy#blahblah-dev.redis.cache.windows.net:6380'
const Fastify = require('fastify')
const fastifyRedis = require('#fastify/redis')
fastify = Fastify({ logger: true, pluginTimeout: 50000 })
fastify.register(fastifyRedis, {
url: process.env.REDIS_URL,
enableAutoPipelining: true,
})
This all works fine run locally using npm start.
When I dockerise it, though, I get an error, which looks like it is caused by not being able to connect to the Redis instance
redisutils_1 | > node index.js
redisutils_1 |
redisutils_1 | /usr/src/node_modules/ioredis/built/redis/event_handler.js:175
redisutils_1 | self.flushQueue(new errors_1.MaxRetriesPerRequestError(maxRetriesPerRequest));
redisutils_1 | ^
redisutils_1 |
redisutils_1 | MaxRetriesPerRequestError: Reached the max retries per request limit (which is 20). Refer to "maxRetriesPerRequest" option for details.
redisutils_1 | at Socket.<anonymous> (/usr/src/node_modules/ioredis/built/redis/event_handler.js:175:37)
redisutils_1 | at Object.onceWrapper (node:events:628:26)
redisutils_1 | at Socket.emit (node:events:513:28)
redisutils_1 | at TCP.<anonymous> (node:net:313:12)
redisutils_1 |
redisutils_1 | Node.js v18.9.0
What have I missed?
you mostly will need to run your container with --network host as your container runnning inside private network and can't reach your network to communicate with any external services.
I discovered the issue.
2 things.
(The dumb one) make sure any environment variable settings (like the rediss URL) are actually being set!
The Redis server was refusing the connection due to certificate issues. I was using bullseye-slim and had to change to alpine and add a step to fix that
FROM node:alpine
RUN apk update && apk add ca-certificates && update-ca-certificates
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
RUN npm install --production --silent && mv node_modules ../
COPY . .
EXPOSE 3000
RUN chown -R node /usr/src/app
USER node
CMD ["npm", "start"]
Namely
RUN apk update && apk add ca-certificates && update-ca-certificates
I have a docker container running via docker-compose with the command as running nestjs in dev mode:
FROM node:16-alpine as base
RUN apk add --no-cache libc6-compat tini
FROM base as dev
ENV NODE_ENV development
USER node
WORKDIR /home/node
# copy all files over
COPY --chown=node:node ./ ./
RUN mkdir -p ./my-app/dist/shared/grpc
RUN chown -R node:node ./my-app/dist
RUN chown -R node:node ./my-app/dist/shared/grpc
My grpc files are in a shared project. the full structure is:
services/shared
services/my-app
The shared project has grpc files inside the directory shared/grpc.
NestJS copies these over to it's dist folder when building. As this is dev, that's every code change or on docker error:
my-app/nest-cli.json:
{
"collection": "#nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"assets": [
{
"include": "../../shared/grpc/*.proto",
"outDir": "./dist/shared/grpc"
}
],
"watchAssets": true
},
"entryFile": "/my-app/src/main"
}
NestJS seems to detect 0 errors, but fails on the copying of the grpc files:
my-app_1 | [7:06:11 AM] Found 0 errors. Watching for file changes.
my-app_1 |
my-app_1 | node:fs:1828
my-app_1 | handleErrorFromBinding(ctx);
my-app_1 | ^
my-app_1 |
my-app_1 | Error [ShellJSInternalError]: EPERM: operation not permitted, chmod 'dist/shared/grpc/apps.proto'
my-app_1 | at Object.chmodSync (node:fs:1828:3)
my-app_1 | at copyFileSync (/home/node/my-app/node_modules/shelljs/src/cp.js:78:8)
my-app_1 | at /home/node/my-app/node_modules/shelljs/src/cp.js:298:7
my-app_1 | at Array.forEach (<anonymous>)
my-app_1 | at Object._cp (/home/node/my-app/node_modules/shelljs/src/cp.js:243:11)
my-app_1 | at Object.cp (/home/node/my-app/node_modules/shelljs/src/common.js:384:25)
my-app_1 | at AssetsManager.actionOnFile (/home/node/my-app/node_modules/#nestjs/cli/lib/compiler/assets-manager.js:95:19)
my-app_1 | at FSWatcher.<anonymous> (/home/node/my-app/node_modules/#nestjs/cli/lib/compiler/assets-manager.js:70:47)
my-app_1 | at FSWatcher.emit (node:events:520:28)
my-app_1 | at FSWatcher.emitWithAll (/home/node/my-app/node_modules/chokidar/index.js:540:8) {
my-app_1 | errno: -1,
my-app_1 | syscall: 'chmod',
my-app_1 | code: 'EPERM',
my-app_1 | path: 'dist/shared/grpc/apps.proto'
my-app_1 | }
my-app_1 | error Command failed with exit code 1.
my-app_1 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
my-app_1 | yarn run v1.22.17
However I can't work out why - it has ownership of all the folders it needs to access. Here's my docker-compose:
version: '3.8'
services:
my-app:
build:
context: .
target: dev
dockerfile: ./my-app/Dockerfile
restart: always
user: node
ports:
- 3003:3000
volumes:
- ./my-app:/home/node/my-app
- ./shared:/home/node/shared
working_dir: /home/node/my-app
command: yarn run start:dev
volumes:
my-app:
Edit 1
After removing USER node from Dockerfile and docker-compose this works. But that means node is running as root which is not OK and not a secure solution. I have even tried adding RUN chmod -R 777 /home/node within Dockerfile and that doesnt work. There must be something behind the scenes in nestjs that needs specific permissions but I can't figure out what.
Bit late to the party, but it was my nest-cli.json file that was causing the issue for me.
under compilerOptions I listed assets that aren't normally watched by Nest (ie: .proto or in my case .ejs files). Removing that line fixed it for me, so it had to do with me running the app in --watch mode and it needing to hot reload that file and not having permissions to copy it.
nest-cli.json:
{
"collection": "#nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"assets": [
"app/**/**/*.ejs"
],
"watchAssets": true
}
}
I have built a Docker Compose project which worked without problems in my container until Ubuntu 18.04.
Now I have updated the project to version Ubunut 20.04 and I get the following error message when starting a shell script Docker Entrypoint:
#!/usr/bin/env bash
if [ ! -f /usr/local/etc/piler/config-site.php ]
then
sleep 20
cd /root/mailpiler/piler/
cp util/postinstall.sh util/postinstall.sh.bak
sed -i "s/ SMARTHOST=.*/ SMARTHOST="\"$MAILSERVER_DOMAIN\""/" util/postinstall.sh
sed -i 's/ WWWGROUP=.*/ WWWGROUP="www-data"/' util/postinstall.sh
sed -i "s/ "
echo -e "y\n\n$PILER_DB_HOST\n$MYSQL_DATABASE\n$MYSQL_USER\n$MYSQL_PASSWORD\n$MYSQL_ROOT_PASSWORD\n\n\nY\nY\n" | make postinstall
# echo -e "y\n$PILER_DB_HOST\n\n$MYSQL_DATABASE\n$MYSQL_USER\n$MYSQL_PASSWORD\n$MYSQL_ROOT_PASSWORD\n\n\n\ny\ny\n" | make postinstall
fi
The command echo -e "y\n\n$PILER_DB_HOST\n$MYSQL_DATABASE\n$MYSQL_USER\n$MYSQL_PASSWORD\n$MYSQL_ROOT_PASSWORD\n\n\nY\nY\n" | make postinstall went without problems so far but since Ubuntu 20.04 the following error is coming:
app_1 | This is the postinstall utility for piler
app_1 | It should be run only at the first install. DO NOT run on an existing piler installation!
app_1 |
app_1 |
app_1 | Continue? [Y/N] [N]
app_1 |
app_1 | Please enter the webserver groupname [www-data]
app_1 | Please enter mysql hostname [localhost]
app_1 | Please enter mysql database [piler]
app_1 | Please enter mysql user name [piler] stty:
'standard input': Inappropriate ioctl for device
'standard input': Inappropriate ioctl for device
app_1 | make: *** [Makefile:126: postinstall] Error 1
The script:
https://bitbucket.org/jsuto/piler/src/master/util/postinstall.sh.in
I'm sure it has something to do with the stty mode and Docker, but I don't know how to fix it.
By the way the script works without dockerized under Ubuntu 20.04 without problems.
My Docker-Compose file:
version: "3.2"
services:
app:
build:
context: ./docker/images
stdin_open: true
tty: true
env_file: .env
depends_on:
- db
ports:
- "25:25"
- "80:80"
restart: always
volumes:
- ./docker/data/piler-local:/usr/local/etc/piler
- ./docker/data/piler-data:/var/piler
db:
image: mariadb:10.4
env_file: .env
restart: always
ports:
- "3306:3306"
volumes:
- ./docker/data/mysql-data:/var/lib/mysql