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:

  • docker/fig: port forwarding to guest machine does not work on MacOS
  • Build vs Runtime environment variables
  • How can I use the Docker Registry API V2 to delete an image from a private registry?
  • Would Docker swarm assist me with managing containers with specific environment variables?
  • How to check the configuration of Docker (volume, devicemapper, ..) after deleting many files ?
  • Can't use 127.0.0.1 to connect mysql server docker container, but can use IP?
  • 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
    

  • Cannot connect to PostgreSQL in Docker through PHP
  • Docker FATA[0000] on Mac
  • Can not access wordpress configured in Docker even though its status is running
  • docker - cannot find aws credentials in container although they exist
  • Docker build time arguments
  • stuck at command “sbt compile” in docker ubuntu
  • 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.