I am trying to set up a docker-compose service adding my own env variables and setting the values.
My service is based on a custom image I’m creating and inside this I’m running some custom scripts I have.
However when I’m running the service and the images start building it results in an error.
If I don’t run the script inside my Docker image but comment it and wait for the container to up, then go inside of the container and execute the script inside the container, the script executes without any issues.
So the issue is when building the image
server-init:
build:
context: ./server
dockerfile: server-init.dockerfile
image: server-init:1.16.1
environment:
API_ADDR: "http://server:5000"
UI_USERNAME: "admin"
UI_PASSWORD: "pass"
restart: unless-stopped
This is the Dockerfile:
# base image
FROM ubuntu:20.04
# download dependencies
RUN apt-get update &&
apt-get install -y curl &&
apt-get install -y jq
# add script files
COPY ./scripts/init.sh /scripts/init.sh
# set working directory
WORKDIR scripts
# start init process
RUN sh init.sh
# set default command to start a bash shell
CMD ["tail", "-f", "/dev/null"]
This is the script:
# don't forget about lini ending UNIX should be LF
#!/bin/sh
base_url=$(sh -c 'echo $API_ADDR')
# Init request
curl --request POST --data '{"init":'true'}' "$base_url/init"
This is the output when building the image:
=> ERROR [server-init 14/14] RUN sh init.sh 0.5s
------
> [server-init 14/14] RUN sh init.sh:
0.444 curl: (3) URL using bad/illegal format or missing URL
------
failed to solve: process "/bin/sh -c sh init.sh" did not complete successfully: exit code: 3
Corneliu CM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.