I have developed a docker app that reads data from a folder on my server (/myapp1/app/data). The data are updated daily in this folder. If I run the docker app on my domain, the app reads the data from the folder, but when these data are updated the app doesn't read the new data, it only reads the old data. If I down the container and run it again, then the app does read the new data.
My dockerfile is the following:
# get shiny server and R from the rocker project
FROM rocker/shiny:4.0.5
RUN apt-get update && apt-get install -y \
sudo \
gdebi-core \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libxt-dev \
libssl-dev \
libxml2 \
libxml2-dev \
libsodium-dev
# install R packages required
RUN R -e "install.packages(c('shiny', 'shinythemes', 'dygraphs', 'shinyWidgets', 'manipulateWidget', 'DT', 'zoo', 'shinyjs','emayili', 'wordcloud2', 'rmarkdown', 'xts', 'shinyauthr', 'curl', 'jsonlite', 'httr', 'lubridate'), repos='http://cran.rstudio.com/')"
# copy the app directory into the image
WORKDIR /myapp1/app
COPY app .
# run app
EXPOSE 8090
CMD ["R", "-e", "shiny::runApp('/myapp1/app', host = '0.0.0.0', port = 8090)"]
My docker-compose.yml file is the following:
version: "3.7"
services:
app1:
image: myapp1image
container_name: myapp1container
expose:
- "8090"
environment:
- VIRTUAL_PORT=8090
- VIRTUAL_HOST=myapp1.net,www.myapp1.net
- LETSENCRYPT_HOST=myapp1.net,www.myapp1.net
- LETSENCRYPT_EMAIL=info#myapp1.net
volumes:
- /myapp1/app/data:/myapp1/app/data
networks:
- mynetwork
networks:
mynetwork:
external : true
My app should read the updated data without having to down and run the container every time the data is updated, so I would appreciate a solution to the problem raised above.
Related
In the process of integrating the docker file into my previous sample project so everything was automated for easy code sharing and execution. I have some dockerize problem and tried to solve it but to no avail. Hope someone can help. Thank you. Here is my problem:
My repository: https://github.com/ThanhDeveloper/WebApplicationAspNetCoreTemplate
Branch for dockerize (my problem in macOS):
https://github.com/ThanhDeveloper/WebApplicationAspNetCoreTemplate/pull/1
Docker file:
# syntax=docker/dockerfile:1
FROM node:16.11.1
FROM mcr.microsoft.com/dotnet/sdk:5.0
RUN apt-get update && \
apt-get install -y wget && \
apt-get install -y gnupg2 && \
wget -qO- https://deb.nodesource.com/setup_6.x | bash - && \
apt-get install -y build-essential nodejs
COPY . /app
WORKDIR /app
RUN ["dotnet", "restore"]
RUN ["dotnet", "build"]
RUN dotnet tool restore
EXPOSE 80/tcp
RUN chmod +x ./entrypoint.sh
CMD /bin/bash ./entrypoint.sh
Docker compose:
version: "3.9"
services:
web:
container_name: backendnet5
build: .
ports:
- "5005:5000"
depends_on:
- database
database:
container_name: postgres
image: postgres:latest
ports:
- "5433:5433"
environment:
- POSTGRES_PASSWORD=admin
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
Commands:
docker-compose build
docker compose up
Problems:
I guess the problem is not being able to run command line dotnet ef database update my migrations. Many thanks for any help.
In your appsettings.json file, you say that the database hostname is 'localhost'. In a container, localhost means the container itself.
Docker compose creates a bridge network where you can address each container by it's service name.
You connection string is
User ID=postgres;Password=admin;Host=localhost;Port=5432;Database=sample_db;Pooling=true;
but should be
User ID=postgres;Password=admin;Host=database;Port=5432;Database=sample_db;Pooling=true;
You also map port 5433 on the database to the host, but postgres listens on port 5432. If you want to map it to port 5433 on the host, the mapping in the docker compose file should be 5433:5432. This is not what's causing your issue though. This just prevents you from connecting to the database from the host, if you need to do that.
I have recently added Docker to my javascript monorepo to build and serve a particular package. Everything is working great, however I did not succeed to make the contents under ./packages/common/dist available to the host directory under ./common-dist which is one of my requirements.
When running docker-compose up, the directory common-dist is indeed created on the host, but the files build under packages/common/dist on the volume are not appearing; the folder stays empty at all.
docker-compose.yml
version: "3"
services:
nodejs:
image: nodejs
container_name: app_nodejs
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
ports:
- "8080:8080"
volumes:
- ./common-dist:/app/packages/common/dist
Dockerfile
FROM node:12-alpine
# Install mozjpeg system dependencies
# #see https://github.com/imagemin/imagemin-mozjpeg/issues/1#issuecomment-52784569
RUN apk --update add \
build-base \
autoconf \
automake \
libtool \
pkgconf \
nasm
WORKDIR /app
COPY . .
RUN yarn install
RUN yarn run common:build
RUN ls /app/packages/common/dist # -> Yip, all files are there!
# CMD ["node", "/app/packages/common/dist/index.js"]
$ docker-compose build
$ docker-compose up # -> ./common-dist appears, but remains empty
Could this be related to some permission issues or am I lacking an understanding of what docker-compose actually does here?
Many thanks in advance!
I have a Dockerfile for a Node.js app that overall looks like this:
FROM ubuntu
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
WORKDIR /app
COPY . /app
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get install -y -q --no-install-recommends \
apt-transport-https \
build-essential \
ca-certificates \
curl \
git \
libssl-dev \
wget \
postgresql-10 postgresql-client-10 postgresql-contrib-10
USER postgres
RUN /etc/init.d/postgresql start &&\
psql --command "CREATE USER warbler WITH SUPERUSER;" &&\
createdb -O warbler warbler_store
# ... node setup stuff ...
# ...
# ...
RUN psql -U warbler -d warbler_store -f db_v1.sql
CMD ["node", "index.js"]
With this though I get the following error message:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
I've looked around online a bit and the majority of solutions I've found seem to say that docker is trying to connect to the host postgres instance, among other questions that have to do with docker containers whose primary purpose is to run PostgreSQL. Is this accurate, and if so is it still possible to run a container-side PostgreSQL instance that's accessible by the primary application?
Apparently it's not good practice to have your database in the same Docker container as your web app. I changed my container structure by just using the postgresql:10 image in another container and having the web app communicate with it via docker-compose. docker-compose allows one to define services and Docker's internal DNS will allow them to communicate with each other
This is what the docker-compose.yaml looks like:
version: '3'
services:
web:
build: .
ports:
- "3000:3000"
volumes:
- .:/app
links:
- db
db:
image: postgres:10
environment:
- POSTGRES_USER=warbler
- POSTGRES_DB=warbler_store
volumes:
- ./db_v1.sql:/docker-entrypoint-initdb.d/db_v1.sql
- dbdata:/var/lib/postgresql/data
volumes:
dbdata:
In this case, in the Dockerfile for web, I set the necessary environment variables so Node connects to the database running at postgresql://db:5432/warbler_store. db resolves via DNS to the IP address of the container running the db service, which is the postgres image container.
I'm trying to connect my Python-Flask app with a Postgres database in a docker environment. I am using a docker-compose file to build my web and db environment.
However, I am getting the following error:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Here is my docker file:
FROM ubuntu:16.04 as base
RUN apt-get update -y && apt-get install -y python3-pip python3-dev postgresql libpq-dev libffi-dev jq
ENV LC_ALL=C.UTF-8 \
LANG=C.UTF-8
ENV FLASK_APP=manage.py \
FLASK_ENV=development \
APP_SETTINGS=config.DevelopmentConfig \
DATABASE_URL=postgresql://user:pw#postgres/database
COPY . /app
WORKDIR /app
RUN pip3 install -r requirements.txt
FROM base as development
EXPOSE 5000
CMD ["bash"]
Here is my Docker-compose file:
version: "3.6"
services:
development_default: &DEVELOPMENT_DEFAULT
build:
context: .
target: development
working_dir: /app
volumes:
- .:/app
environment:
- GOOGLE_CLIENT_ID=none
- GOOGLE_CLIENT_SECRET=none
web:
<<: *DEVELOPMENT_DEFAULT
ports:
- "5000:5000"
depends_on:
- db
command: flask run --host=0.0.0.0
db:
image: postgres:10.6
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=db
I'm building up a nodejs app which is running in the docker container and getting following error
NetworkingError: connect ECONNREFUSED 127.0.0.1:8000"
And If I tried with dynamodb-local:8000 then it will give me following error
NetworkingError: write EPROTO
140494555330368:error:1408F10B:SSLroutines:ssl3_get_record:wrong
version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:252:
I am using the following docker-compose.yml
version: "3"
services:
node_app:
build: .
container_name: 'node_app'
restart: 'always'
command: 'npm run start:local'
ports:
- "3146:3146"
links:
- dynamodb-local
dynamodb-local:
container_name: 'dynamodb-local'
build: dynamodb-local/
restart: 'always'
ports:
- "8000:8000"
Node js docker configuration as follows, node_app
FROM node:latest
RUN mkdir -p /app/node_app
WORKDIR /app/node_app
# Install app dependencies
COPY package.json /app/node_app
#RUN npm cache clean --force && npm install
RUN npm install
# Bundle app source
COPY . /app/node_app
# Build the built version
EXPOSE 3146
#RUN npm run dev
CMD ["npm", "start"]
Dynamo DB local docker configuration as follows, dynamodb-local
#
# Dockerfile for DynamoDB Local
#
# https://aws.amazon.com/blogs/aws/dynamodb-local-for-desktop-development/
#
FROM openjdk:7-jre
RUN mkdir -p /var/dynamodb_local
RUN mkdir -p /var/dynamodb_picstgraph
# Create working space
WORKDIR /var/dynamodb_picstgraph
# Default port for DynamoDB Local
EXPOSE 8000
# Get the package from Amazon
RUN wget -O /tmp/dynamodb_local_latest https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz && \
tar xfz /tmp/dynamodb_local_latest && \
rm -f /tmp/dynamodb_local_latest
# Default command for image
ENTRYPOINT ["/usr/bin/java", "-Djava.library.path=.", "-jar", "DynamoDBLocal.jar", "-sharedDb", "-dbPath", "/var/dynamodb_local"]
CMD ["-port", "8000"]
# Add VOLUMEs to allow backup of config, logs and databases
VOLUME ["/var/dynamodb_local", "/var/dynamodb_nodeapp"]
But when I tried to connect outside docker container to local dynamodb and it will work perfectly.
Please help me to sort out this issue.
Inside the docker container, the DB will be available with the host dynamodb-local:8000.
It might be an SSL issue, please check your apache configuration if you have used the port for other application.
For that case, you can use link dynamo on another port as follows,
#
# Dockerfile for DynamoDB Local
#
# https://aws.amazon.com/blogs/aws/dynamodb-local-for-desktop-development/
#
FROM openjdk:7-jre
RUN mkdir -p /var/dynamodb_local
RUN mkdir -p /var/dynamodb_picstgraph
# Create working space
WORKDIR /var/dynamodb_picstgraph
# Default port for DynamoDB Local
EXPOSE 8004
# Get the package from Amazon
RUN wget -O /tmp/dynamodb_local_latest https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz && \
tar xfz /tmp/dynamodb_local_latest && \
rm -f /tmp/dynamodb_local_latest
# Default command for image
ENTRYPOINT ["/usr/bin/java", "-Djava.library.path=.", "-jar", "DynamoDBLocal.jar", "-sharedDb", "-dbPath", "/var/dynamodb_local"]
CMD ["-port", "8004"]
# Add VOLUMEs to allow backup of config, logs and databases
VOLUME ["/var/dynamodb_local", "/var/dynamodb_nodeapp"]
Now in your docker container, the DB will be available with the host dynamodb-local:8004.