My application image of my nodejs app is pushed to azure container register but my mongo image isnt it. why?
this is my docker file.
FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8085
CMD [ "npm", "start" ]
and this is my docker-compose file.
version: "3"
services:
app:
image: rocketrcontainerregister.azurecr.io/rocketr_app:dev
build:
context: .
dockerfile: ./Dockerfile
ports:
- "8085:8085"
depends_on:
- mongo
links:
- mongo
container_name: rocketrapi
mongo:
image: mongo
ports:
- "27017:27017"
container_name: mongodb
Related
I have a NestJs App, when I deploy the app on my ubuntu server using docker compose up --build, after a few hours, data will be deleted automatically.
Dockerfile:
FROM node:14.16.0-alpine3.13
RUN addgroup app && adduser -S -G app app
RUN mkdir /app && chown app:app /app
USER app
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "run", "start:prod"]
And my docker-compose file:
version: '3'
services:
api:
depends_on:
- db
restart: unless-stopped
build:
context: .
dockerfile: Dockerfile
ports:
- '3000:3000'
environment:
DB_URL: mongodb://db_myapp
JWP_PRIVATE_KEY: test
PORT: 3000
db:
image: mongo:xenial
container_name: db_myapp
volumes:
- myapp:/data/db
ports:
- '27017:27017'
volumes:
myapp:
I tried attaching the volume to a local directory in my server:
db:
image: mongo:xenial
container_name: db_myapp
volumes:
- ../myapp_db_data:/data/db
ports:
- '27017:27017'
But I faced this error when running the app:
MongooseServerSelectionError: getaddrinfo EAI_AGAIN db_myapp
I'm looking for a way to have persistent data of my app after docker compose up --build, because I need to update the backend app on production
I have the following docker-compose.yml
version: '2'
services:
db:
image: postgres
container_name: postgres
restart: unless-stopped
environment:
POSTGRES_PASSWORD: mypassword
POSTGRES_USER: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
volumes:
- ./data/db:/var/lib/postgresql/data
adminer:
image: adminer
restart: unless-stopped
ports:
- 8080:8080
nginx-reverse-proxy:
image: nginx:1.19.8
container_name: reverse-proxy-container
volumes:
- ./proxy/config:/etc/nginx
restart: unless-stopped
ports:
- 8000:8000
sheet-service:
image: sheetservice:latest
build:
context: ./microservices/sheet-service
dockerfile: Dockerfile
container_name: sheet-service
restart: unless-stopped
ports:
- 3002:3002
depends_on:
- "db"
- "nginx-reverse-proxy"
only sheet-service container starts, when executing the docker script with the command docker-compose up --build. When I check the running processes by typing docker ps -a the output shows this . The name of container strangely is not sheet-service as specified in docker-compose.yml.
The Dockerfile of sheet-service:
FROM node:14.15.0
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run start
The script's starting logs:
> docker-compose up --build
Building sheet-service
Sending build context to Docker daemon 73.29MB
Step 1/6 : FROM node:14.15.0
---> b90fa0d7cbd1
Step 2/6 : WORKDIR /usr/src/app
---> Using cache
---> 6ce9a5a77956
Step 3/6 : COPY package*.json ./
---> Using cache
---> d9c528ab2b74
Step 4/6 : RUN npm ci --only=production
---> Using cache
---> 221d8f411055
Step 5/6 : COPY . .
---> Using cache
---> 025dba9ebb44
Step 6/6 : RUN npm run start
---> Running in 84c8c1b8a9d8
> sheet-service#1.0.0 start /usr/src/app
> node src/index.js
Server running on port 3002!
If I comment out the lines where the sheet-service is defined like this
version: '2'
services:
db:
image: postgres
container_name: postgres
restart: unless-stopped
environment:
POSTGRES_PASSWORD: mypassword
POSTGRES_USER: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
volumes:
- ./data/db:/var/lib/postgresql/data
adminer:
image: adminer
restart: unless-stopped
ports:
- 8080:8080
nginx-reverse-proxy:
image: nginx:1.19.8
container_name: reverse-proxy-container
volumes:
- ./proxy/config:/etc/nginx
restart: unless-stopped
ports:
- 8000:8000
# sheet-service:
# image: sheetservice:latest
# build:
# context: ./microservices/sheet-service
# dockerfile: Dockerfile
# container_name: sheet-service
# restart: unless-stopped
# ports:
# - 3002:3002
# depends_on:
# - "db"
# - "nginx-reverse-proxy"
all other containers start successfully. Why sheet-service stop other containers from running and why it shows with different than specified name?
If I run containers one by one with docker-compose run container_name all containers start successfully without errors or warnings.
docker-compose config:
services:
adminer:
image: adminer
ports:
- published: 8080
target: 8080
restart: unless-stopped
db:
container_name: postgres
environment:
POSTGRES_DB: postgres
POSTGRES_PASSWORD: mypassword
POSTGRES_USER: postgres
image: postgres
ports:
- published: 5432
target: 5432
restart: unless-stopped
volumes:
- /home/myuser/Coding/myproject/data/db:/var/lib/postgresql/data:rw
nginx-reverse-proxy:
container_name: reverse-proxy-container
image: nginx:1.19.8
ports:
- published: 8000
target: 8000
restart: unless-stopped
volumes:
- /home/myuser/Coding/myproject/proxy/config:/etc/nginx:rw
sheet-service:
build:
context: /home/myuser/Coding/myproject/microservices/sheet-service
dockerfile: Dockerfile
container_name: sheet-service
depends_on:
db:
condition: service_started
nginx-reverse-proxy:
condition: service_started
image: sheetservice:latest
ports:
- published: 3002
target: 3002
restart: unless-stopped
version: '2'
Docker version 20.10.7, build f0df350
docker-compose version 1.29.1, build c34c88b2
Ubuntu 16.04.7 LTS
Your Dockerfile ...
FROM node:14.15.0
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run start
... contains a last line of RUN npm run start. This RUN instruction is carried out as part of the docker image build and starts the node server - the build will then 'hang' while that stays running and thus cause subsequent steps in the docker compose startup not to ever start (never mind complete).
I presume you mean to execute the node process as part of the actual docker container startup process and so you should change your RUN npm run start line to be an ENTRYPOINT npm run start as that will make the node startup process execute when the container starts.
I'm very new to Docker and I'm confused about how to backup the mongodb database. I'm using 2 containers, both connected through a network.
the express app container
along with the MongoDB container
Based on this, a docker image/script needs to be written so that the database gets uploaded at intervals to the cloud such as google drive.
My current files are as follows:
docker-compose.yml
version: "3.7"
services:
app:
build: .
container_name: "server-app-service"
#restart: always
ports:
- ${PORT}:${PORT}
working_dir: /oj-server
volumes:
- ./:/oj-server
links:
- mongodb
env_file:
- .env.production
environment:
- MONGO_URI=mongodb://mongodb:27017/beta1
command: ["yarn", "start"]
mongodb:
image: mongo:latest
container_name: "mongodb-service"
ports:
- 27017:27017
volumes:
- mongodb-data:/data/db
volumes:
mongodb-data:
Dockerfile
FROM node:16.14.2-alpine
RUN apk add --no-cache libc6-compat build-base g++ openjdk11 python3
WORKDIR /oj-server
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
# expose the port
EXPOSE ${PORT}
When I use docker compose it performs perfectly the application, however, when I use docker run nothing happens
I have a API Rest (Express & Mongodb) with nginx proxy-pass.
Docker file:
FROM node:8-alpine
EXPOSE 3000
ARG NODE_ENV
ENV NODE_ENV $NODE_ENV
RUN mkdir /app
WORKDIR /app
ADD package.json yarn.lock /app/
RUN yarn --pure-lockfile
ADD . /app
CMD ["yarn", "start"]
Docker compose:
version: "2"
services:
api:
build: .
environment:
- NODE_ENV=production
command: yarn start
volumes:
- .:/app
ports:
- "3000:3000"
tty: true
depends_on:
- mongodb
restart: always
nginx:
image: nginx
depends_on:
- api
ports:
- "80:80"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- mongodb
restart: always
mongodb:
image: mongo
ports:
- "27017:27017"
restart: always
When I use docker compose it performs perfectly the application, however, when I use docker run nothing happens
That seems expected, since docker run would run one image.
As opposed to docker compose, which will run a multi-container Docker application.
You need for all images to run, starting with the right order, in order to anything to happen.
I got that docker-compose.yml:
version: '2'
services:
web:
build: .
ports:
- "3000:3000"
volumes:
- .:/code
depends_on:
- db1
links:
- db1:mongo
db1:
image: mongo
Dockerfile:
FROM node:4.4.2
ADD . /code
WORKDIR /code
RUN npm i
CMD node app.js
I store dump in project files so folder is shared with container. How should look like proccess of restoring dump ? In web container I don't have access to mongoresore commnad ...