Sending a file as a parameter to a container in order to be compiled causes problems

I’m facing some problems when sending a file to a docker container in order to be compiled and executed.

In the folder that I’m running the command I have a “compiler” folder and a file.cpp(a basic hello world”). I’m using this command:

  • ehcache not working in Tomcat Docker image
  • Docker: connection between golang webapp and postgres server refused
  • Fail to connect mysql in running wordpress docker
  • How to connect Emacs' Elpy in-buffer python interpreter to docker container?
  • Ubuntu on Managed VMs using custom runtime
  • Sails doesnt populate on large queries
  • sudo docker run –rm -it -v /compiler/ dockcompiler file.cpp

    And this is the output:

    useradd: warning: the home directory already exists.
    Not copying any file from skel directory into it.
    chgrp: cannot access ‘/code’: No such file or directory
    chmod: cannot access ‘/code’: No such file or directory
    file does not exist

    My Dockerfile:

    FROM ubuntu
    
    RUN apt-get update
    RUN apt-get install -y gcc g++
    
    ADD entrypoint.sh entrypoint.sh
    ADD run-code.sh run-code.sh
    
    ENTRYPOINT ["/bin/bash", "entrypoint.sh"] 
    

    entrypoint.sh

    prog=$1
    uid=$2
    
    if [ -z $1 ]; then
      echo "you must provide a file"
      exit 1
    fi
    
    if [ -z $uid ]; then
      uid=10000
    fi
    
    echo "127.0.0.1 $(hostname)" >> /etc/hosts
    
    groupadd code
    useradd -u "$uid" -G code -d "/compiler" -m codecube 
    chgrp code /code
    chmod 0775 /code
    cd /compiler
    sudo -u codecube /bin/bash /run-code.sh $prog
    

    And the run-code.sh file(it works if I run it in terminal):

     prog=$1
    
    if [ -z $1 ]; then
      echo "you must provide a file"
      exit 1
    fi
    
    if [ ! -f $1 ]; then
      echo "file does not exist"
      exit 1
    fi
    
    extension="${prog##*.}"
    case "$extension" in
      "cpp")
        g++ $prog && ./a.out
        ;;
      "c")
        gcc $prog && ./a.out
        ;;
      "go")
        go run $prog
        ;;
      "pl")
        perl $prog
        ;;
      "py")
        python $prog
        ;;
      "rb")
        ruby $prog
        ;;
      *)
        echo "invalid language"
        exit 1
        ;;
    esac
    

  • Can't connect to django server running inside docker container (Docker for mac)
  • Import broker definitions into Dockerized RabbitMQ
  • how do i run a container so that it is running behind a proxy + on running?
  • Docker PHP and FreeTDS -cannot find freetds in know installation directories
  • “ImportError: No module named _bsddb” when opening shelve in Docker container
  • Migrating dockerized redis to another server
  • One Solution collect form web for “Sending a file as a parameter to a container in order to be compiled causes problems”

    Updated:

    The problem is -m codecube where the it says codecube directory already exists. Also, the /code directory is not present.

    If the user directory is already in place on your docker image (assuming a modified image being used here). Then just skel files copy should do the trick and you can get away without doing useradd. A post here offers more info on this.

    #copy skel files 
    cp -r /etc/skel/. /codecube
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.