How do I write a dockerfile to execute a simple bash script?

TakeSoUp

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?

zegkljan

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I write a dockerfile to execute a simple bash script?

From Dev

How do I create a simple loop daemon bash script?

From Dev

How do I write a Bash script that will ask users to define a variable?

From Dev

How do I write shell script for Redhat Linux bash shell

From Dev

Bash - How do I write a script that will ssh into a given ip?

From Dev

How do I execute a python script on Heroku?

From Dev

How do I execute a command string in BASH?

From Dev

How do I execute a xfconf-query command from a bash script launched with sudo?

From Dev

How do I execute a bash script on my Vagrant from PhpStorm on a Windows PC

From Dev

How to execute a bash script?

From Dev

mysql-workbench, how do I write a bash file command as to launch and open a SQL script to a query tab?

From Dev

How do I write a bash script to report machine states and conditionally ping them?

From Dev

How do I write a bash script that will let users choose the value of the MIRROR environment variable?

From Dev

how do i write a such a bash script that can search, rename, and replace files

From Dev

How do I write a bash script to copy files into a new folder based on name?

From Dev

How do I write a bash menu script so that the options are the contents of a list?

From Dev

How do I write a condition that runs only if a particular file has not already been converted in a bash script?

From Dev

How do I load a simple script?

From Dev

How do I load a simple script?

From Dev

How do I write a script that runs on startup?

From Dev

How do I stop execution of bash script?

From Dev

How do I iterate the arguments in a bash script?

From Dev

How do I maintain sudo in a bash script?

From Dev

How do I run this bash script in ubuntu?

From Dev

How do I concatenate strings in a bash script?

From Dev

How do I iterate the arguments in a bash script?

From Dev

How do I get the directory of the PowerShell script I execute?

From Dev

How do I make a block of script write to another script?

From Dev

How to write a bash script, that logs onto an other machine to do stuff?

Related Related

  1. 1

    How do I write a dockerfile to execute a simple bash script?

  2. 2

    How do I create a simple loop daemon bash script?

  3. 3

    How do I write a Bash script that will ask users to define a variable?

  4. 4

    How do I write shell script for Redhat Linux bash shell

  5. 5

    Bash - How do I write a script that will ssh into a given ip?

  6. 6

    How do I execute a python script on Heroku?

  7. 7

    How do I execute a command string in BASH?

  8. 8

    How do I execute a xfconf-query command from a bash script launched with sudo?

  9. 9

    How do I execute a bash script on my Vagrant from PhpStorm on a Windows PC

  10. 10

    How to execute a bash script?

  11. 11

    mysql-workbench, how do I write a bash file command as to launch and open a SQL script to a query tab?

  12. 12

    How do I write a bash script to report machine states and conditionally ping them?

  13. 13

    How do I write a bash script that will let users choose the value of the MIRROR environment variable?

  14. 14

    how do i write a such a bash script that can search, rename, and replace files

  15. 15

    How do I write a bash script to copy files into a new folder based on name?

  16. 16

    How do I write a bash menu script so that the options are the contents of a list?

  17. 17

    How do I write a condition that runs only if a particular file has not already been converted in a bash script?

  18. 18

    How do I load a simple script?

  19. 19

    How do I load a simple script?

  20. 20

    How do I write a script that runs on startup?

  21. 21

    How do I stop execution of bash script?

  22. 22

    How do I iterate the arguments in a bash script?

  23. 23

    How do I maintain sudo in a bash script?

  24. 24

    How do I run this bash script in ubuntu?

  25. 25

    How do I concatenate strings in a bash script?

  26. 26

    How do I iterate the arguments in a bash script?

  27. 27

    How do I get the directory of the PowerShell script I execute?

  28. 28

    How do I make a block of script write to another script?

  29. 29

    How to write a bash script, that logs onto an other machine to do stuff?

HotTag

Archive