I'm trying to write a docker image to run a simple webserver though netcat.
So I have in my docker build folder:
Dockerfile
index.html
run_netcat_webserver.sh
The run_netcat_webserver.sh
is very simple and it works fine:
#!/bin/bash
while true ; do nc -l 8080 < index.html ; done
Here is my naive Dockerfile that of course is not working:
FROM ubuntu:14.04
CMD run_netcat_webserver.sh
How should I proceed to make this work inside a docker container?
You need to make the script part of the container. To do that, you need to copy the script inside using the COPY
command in the Docker file, e.g. like this
FROM ubuntu:14.04
COPY run_netcat_webserver.sh /some/path/run_netcat_webserver.sh
CMD /some/path/run_netcat_webserver.sh
The /some/path
is a path of your choice inside the container. Since you don't need to care much about users inside the container, it can be even just /
.
Another option is to provide the script externally, via mounted volume. Example:
FROM ubuntu:14.04
VOLUME /scripts
CMD /scripts/run_netcat_webserver.sh
Then, when you run the container, you specify what directory will be mounted as /scripts
. Let's suppose that your script is in /tmp
, then you run the container as
docker run --volume=/tmp:/scripts (rest of the command options and arguments)
This would cause that your (host) directory /tmp
would be mounted under the /scripts
directory of the container.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments