Reputation: 43
I am new to docker and i worked in one small scenario. Situation is, i need to pass different values during each docker container creation using docker run command.
FROM nginx:alpine
ARG files
ENV files=$files
COPY $files /usr/share/nginx/html
For building docker image using docker build . -t sample-ui
command.
while running the docker container, i am passing one html file like below.
docker run -p 8090:80 -e files=sample1.html sample-ui
Now i just checked in browser, http://localhost:8090/sample1.html and it works fine and i am able to see the sample1.html web page.
Now i am going to create another container on top of same docker image with different html page as environment value.
docker run -d -p 8091:80 -e files=sample2.html sample-ui
But now the second container also have sample1.html only but not sample2.html. Means http://localhost:8091/sample2.html is not working. http://localhost:8091/sample1.html is working.
Anyone help me to resolve this issue.
Upvotes: 0
Views: 307
Reputation: 43
Now I am successfully pass environmental variable values during docker container creation( docker run Image name).
docker run -d -p 8091:80 -e "files=sample2.html" sample-ui
Actually we need to give double quote as mentioned above.
By this way, I am able to create different docker container with dynamic html files
Upvotes: 0
Reputation: 6471
From Dockerfile
COPY $files /usr/share/nginx/html
This COPY
command will execute while building the docker image using the Dockerfile.
While I build docker image using above Dockerfile It copied all files and directory of my current folder into /user/share/nginx/html
folder.
To ensure run following:
docker exec -it <container id> sh
/ # ls /user/share/nginx/html
Now i just checked in browser, http://localhost:8090/sample1.html and it works fine and i am able to see the sample1.html web page.
So, In your case there might be sample1.html
filed present while you are building image. That's why above url working.
sample2.html
was not present, so it's not working
Upvotes: 1