How to pass external application.yaml file to docker container - spring-boot

This is my docker file
FROM openjdk:8-jdk-alpine AS base
WORKDIR /app
FROM base as builder
COPY . .
RUN chmod +x gradlew && ./gradlew build
FROM base
RUN adduser -D -g dgm dgm
RUN chown dgm:dgm /app
USER dgm
COPY --from=builder --chown=dgm:dgm /app/build/libs/demo-0.0.1-SNAPSHOT.jar ./
COPY --from=builder --chown=dgm:dgm /app/build/libs/application.yaml ./config/application.yaml
#COPY --from=builder --chown=dgm:dgm /app/build/libs/application.yaml .
#RUN chmod 777 config/* && chmod 777 config
# Run the jar file
ENTRYPOINT ["java", "-jar", "demo-0.0.1-SNAPSHOT.jar"]
CMD ["--spring.config.location=config/application.yaml"]
VOLUME [ "/app/config" ]
How to run this docker image with external application.yaml file.
I tried few ways.
docker run -it demo --entrypoint "/home/durgpal/application.yaml"
dokcer run it demo /home/durgpal/application.yaml

Did you try using a volume?
docker run -v /home/durgpal/application.yaml:/app/config/application.yaml demo

Related

I can't run shell script

I made a dockerfile that uses the latest alpine and copies test.sh to /src.
I run the container and open up the CLI window in docker. Its path is /src and if I enter command ls I get the test.sh file.
But when I try to run it by either running test.sh or ./test.sh it states /bin/sh: .test.sh: not found.
I added RUN apk add --no-cache --upgrade bash before setting WORKDIR in my Dockerfile.
Dockerfile
FROM alpine:latest
RUN apk add --no-cache --upgrade bash
WORKDIR /src
COPY . .
test.sh
#!/bin/sh
echo "Test"
Content of host directory:
Dockerfile
test.sh
Opened up the docker cli for the container and run:
chmod +x test.sh
Then run ls -l and got -rwxr-xr-x on the file. then tried to run:
/bin/sh: ./test.sh: not found

Running docker as sibling

I am trying to run a container (hello-world) as a sibling from another container (dev).
But, container script is not able to access "Docker". I am getting
Docker not found error
Here is what I am doing: dev Dockerfile downloads the docker image Like
ENV DOCKER_VERSION=19.03.8
RUN curl -sfL -o docker.tgz
"https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VERSION}.tgz" && \
tar -xzf docker.tgz docker/docker --strip=1 --directory /usr/local/bin && \
rm docker.tgz
RUN ["chmod","+x","./script.sh"]
ENTRYPOINT ["sh","./script.sh"]
script.sh is:
#!/bin/bash
docker run hello-world
Docker Build command:
docker build -t dev .
Docker run command:
docker run -v /var/run/docker.sock:/var/run/docker.sock <container_image>

Running a git clone and rsync bash script during a docker compose build

docker-compose:
version: '3'
services:
php:
build:
context: ./
dockerfile: ./Dockerfile
volumes:
- ./wordpress:/var/www/html:rw
restart: always
Dockerfile:
FROM php:7-fpm-alpine
RUN apk add --quiet --no-cache bash git rsync
COPY ./scripts/php/install-wordpress.sh /install-wordpress.sh
RUN chmod +x /install-wordpress.sh \
&& sh /install-wordpress.sh
install-wordpress.sh:
#!/bin/bash
set -ex
git clone --depth=1 --no-tags https://github.com/roots/bedrock.git /tmp/bedrock
rsync -rp /tmp/bedrock/ /var/www/html/
exec "$#"
When I run docker-compose build php; docker-compose up -d; then docker-compose exec php /bin/bash and ls in /var/www/html/ the directory is empty however bedrock has been cloned into tmp
The Docker image should work as it supposed to work if you run it without docker-compose.
try to run
docker run --rm --name testc -it your_image bash -c "ls /var/www/html/"
This issue is with volumes: it hides everything from Docker image. remove the
volumes:
- ./wordpress:/var/www/html:rw
And it should work fine.
version: '3'
services:
php:
build:
context: ./
dockerfile: ./Dockerfile
restart: always
update:
You can not view the files even if you mount the empty directory of the host, the reason is you cloned repo at build, not at run time.
To view files in host without exec in Docker you must clone at run time and you should be moved you script from to entry point. you current script install-wordpress.sh is not entrypoint it's just like other RUN commands of the Dockerfile.
FROM php:7-fpm-alpine
RUN apk add --quiet --no-cache bash git rsync
COPY install-wordpress.sh /install-wordpress.sh
RUN chmod +x /install-wordpress.sh
entrypoint ["/install-wordpress.sh"]
CMD ["php-fpm"]
entrypoint.sh
#!/bin/bash
set -ex
git clone --depth=1 --no-tags https://github.com/roots/bedrock.git /tmp/bedrock
rsync -rp /tmp/bedrock/ /var/www/html/
exec "$#"
so now if you run
docker run --rm --name testc -v $PWD/:/var/www/html/ -it your_image
It should work fine and you will able to see files wordpress files also clone files and folder as well.
version: '3'
services:
php:
build:
context: ./
dockerfile: ./Dockerfile
volumes:
- ./wordpress:/var/www/html:rw
restart: always

Dockerfile commands not executing in MacOS

I am trying to build a container using docker file which has some statements to execute as below:
# Create folder for caching files
RUN mkdir -p /Library/WebServer/docroot/publish
RUN chown -R daemon:daemon /Library/WebServer/docroot
I am using below command to build :
$ docker build --no-cache -t dispatcher-apache -f Dockerfile
I can see the below execution :
Step 7/10 : RUN mkdir -p /Library/WebServer/docroot/publish
---> Running in 4c8f7c3e2238
But the file isn't created on that location when I check.
-bash: cd: /Library/WebServer/docroot/publish: No such file or directory
However, if I create commands from terminal, it works fine.
Dockerfile :
FROM httpd:2.4
# Copy dispatcher module
RUN mkdir -p /private/libexec/apache2/
COPY ./apache2-modules/ /private/libexec/apache2/
RUN ln -s /private/libexec/apache2/dispatcher-apache2.4-4.2.3.so /private/libexec/apache2/mod_dispatcher.so
# Copy new apache dependencies
RUN mkdir -p /private/etc/apache2/conf
COPY ./publish/etc/httpd/conf.d/ /private/etc/apache2/conf/
# Create folder for caching files
RUN mkdir -p /Library/WebServer/docroot/publish
RUN chown -R daemon:daemon /Library/WebServer/docroot
# Create folder for log files
RUN mkdir -p /private/var/log/apache2
# Replace httpd.conf with enabled modules
COPY ./my-httpd.conf /usr/local/apache2/conf/httpd.conf
EDIT after some help:
Now after build, I started the container and below is the error
$ docker run -dit -e HOSTIP=$(ipconfig getifaddr en0) --rm --name dispatcher-app -p 8080:80 dispatcher-apache
6a032a50be846bef06027976b990da27bcb446c28d582cf6c3a4dc4ad4361e1c
$ docker exec -it dispatcher-app /bin/bash
Error: No such container: dispatcher-app
Any troubleshooting tips?

Starting container process caused "exec: \"/tmp/run.sh\": permission denied": unknown

I have a Dockerfile
FROM composer:1.8.5 as build_stage
COPY . /src
WORKDIR /src
RUN composer install
FROM alpine:3.8
RUN apk --no-cache add \
php7 \
php7-mbstring \
php7-session \
php7-openssl \
php7-tokenizer \
php7-json \
php7-pdo \
php7-pdo_pgsql \
php7-pgsql
COPY --from=build_stage /src /src
RUN ls -al
RUN set -x \
addgroup -g 82 -S www-data \
adduser -u 82 -D -S -G www-data www-data
WORKDIR /src
RUN ls -al
RUN chmod -R 777 storage
RUN sudo chmod +x run.sh
copy ./run.sh /tmp
ENTRYPOINT ["/tmp/run.sh"]
run.sh
#!/bin/sh
cd /app
php artisan migrate:fresh --seed
php artisan serve --host=0.0.0.0
and when I run, I kept getting
How would one go about and debug this further?
RUN sudo chmod +x run.sh
copy ./run.sh /tmp
You are copying a fresh copy from the build context without execute permission onto /tmp/run.sh. Try to change those command for the following.
RUN chmod +x run.sh
RUN cp run.sh /tmp
Note that sudo isn't needed because you are already as root.
The issue is in this block:
RUN sudo chmod +x run.sh
copy ./run.sh /tmp
ENTRYPOINT ["/tmp/run.sh"]
You make run.sh executable, then overwrite it with a non-executable version. Switching the order of the two commands should fix it:
COPY ./run.sh /tmp
RUN chmod +x /tmp/run.sh
ENTRYPOINT ["/tmp/run.sh"]

Resources