Reputation: 183
I would like to change the content of a configuration file when starting a docker nginx container via docker-compose. I copied a script containing a sed command to the "docker-entrypoint.d" directory in order to be executed on startup. Note: nginx 1.19 introduced an entrypoint and a few scripts to alter the configuration on the start of the container.
However, I encounter the following issues:
Here are the relevant files:
Dockerfile:
# 1.) build
FROM node:14.16.1-alpine3.13 AS builder
WORKDIR /app
COPY . .
# 2.) target image
FROM nginx:1.21.3-alpine
COPY --from=builder /app/myinit.sh ./docker-entrypoint.d
COPY --from=builder /app/env.js /usr/share/nginx/html
#ENTRYPOINT ["nginx", "-g", "daemon off;"]
myinit.sh:
sed -i 's~__env.apiUrlRoot.*~__env.apiUrlRoot = '$MYENV';~g' /usr/share/nginx/html/env.js
env.js:
(function (window) {
window.__env.apiUrlRoot = 'http://localhost:9090';
}(this));
docker-compose.yml:
version: '3.8'
services:
mytest:
image: 'tst:latest'
build:
context: .
dockerfile: Dockerfile
container_name: tst1
environment:
- MYENV=SomeValue
docker-compose command:
docker-compose -f docker-compose.yml up --build
Upvotes: 0
Views: 1536
Reputation: 183
I found the root cause of the first issue: "myinit.sh" contained windows style CRLF instead of unix style LF. I changed that and the shell script executed properly. BTW: you can run "dos2unix " to replace CRLF by LF.
Upvotes: 1