Running a Docker image command in a mounted folder - clojure

I'm trying to execute lein run in a Clojure Docker image out of a mounted folder that is not /, but when I try to cd into a folder, Docker complains with unable to locate cd:
docker run -v /root/chortles:/test -i jphackworth/docker-clojure cd /test && lein run
=> Unable to locate cd
How do I instruct Leiningen to run in a different folder, or tell Docker to change the directory prior to running my command?

You can use -w param for docker run. This parameter is useful for specifying working directory within container.
docker run -w /test -v /root/chortles:/test -i jphackworth/docker-clojure lein run

The best bet is to add a shell script to the docker image and call that.
Have a script called, say lein-wrapper.sh, install in in /usr/local/bin. The script should sort out the environment for leiningen and then call it. Something like this:
#!/bin/sh
export PATH=${LEININGEN_INSTALL}:${PATH}
cd /test
lein $#
You can set
ENTRYPOINT["/usr/local/bin/lein-wrapper.sh"]
In your Dockerfile
And invoke it as:
# Will call /usr/local/bin/lein-wrapper.sh run
# which will call lein run
docker run -v /root/chortles:/test -i jphackworth/docker-clojure run
# or run lein deps...
docker run -v /root/chortles:/test -i jphackworth/docker-clojure deps

cd is a bash builtin, not a command. You can use bash -c 'cd /test && lein run'. Better yet, do as #Jiri states and use the -w parameter to set the working directory of the container, then just use lein run to start your app.

Related

ENTRYPOINT just refuses to exec or even shell run

This is my 3rd day of tear-your-hair-out since the weekend and I just cannot get ENTRYPOINT to work via gitlab runner 13.3.1, this for something that previously worked with a simple ENTRYPOINT ["/bin/bash"] but that was using local docker desktop and using docker run followed by docker exec commands which worked like a synch. Essentially, at the end of it all I previously got a WAR file built.
Currently I build my container in gitlab runner 13.3.1 and push to s3 bucket and then use the IMAGE:localhost:500/my-recently-builtcontainer and then try and do whatever it is I want with the container but I cannot even get ENTRYPOINT to work, in it's exec form or in shell form - atleast in the shell form I get to see something. In the exec form it just gave "OCI runtime create failed" opaque errors so I shifted to the shell form just to see where I could get to.
I keep getting
sh: 1: sh: echo HOME=/home/nonroot-user params=#$ pwd=/ whoami=nonroot-user script=sh ENTRYPOINT reached which_sh=/bin/sh which_bash=/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin; ls -alrth /bin/bash; ls -alrth /bin/sh; /usr/local/bin/entrypoint.sh ;: not found
In my Dockerfile I distinctly have
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN bash -c "ls -larth /usr/local/bin/entrypoint.sh"
ENTRYPOINT "echo HOME=${HOME} params=#$ pwd=`pwd` whoami=`whoami` script=${0} ENTRYPOINT reached which_sh=`which sh` which_bash=`which bash` PATH=${PATH}; ls -alrth `which bash`; ls -alrth `which sh`; /usr/local/bin/lse-entrypoint.sh ;"
The output after I build the container in gitlab is - and I made sure anyone has rights to see this file and use it - just so that I can proceed with my work
-rwxrwxrwx 1 root root 512 Apr 11 17:40 /usr/local/bin/entrypoint.sh
So, I know it is there and all the chmod flags indicate anybody can look at it - so I am so perplexed why it is saying NOT FOUND
/usr/local/bin/entrypoint.sh ;: not found
entrypoint.sh is ...
#!/bin/sh
export PATH=$PATH:/usr/local/bin/
clear
echo Script is $0
echo numOfArgs is $#
echo paramtrsPassd is $#
echo whoami is `whoami`
bash --version
echo "About to exec ....."
exec "$#"
It does not even reach inside this entrypoint.sh file.

Installing Anaconda on Amazon Elastic Beanstalk to use in Django application

I have a Django application which it's deployed to Amazon Elastic Beanstalk. I have to install anaconda for installing pythonocc-core package. I have created a .config file in .ebextensions folder and add the anaconda path in my wsgi.py file such as below and I have deployed it successfully.
.config file:
commands:
00_download_conda:
command: 'wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh'
test: test ! -d /anaconda
01_install_conda:
command: 'bash Anaconda3-2020.02-Linux-x86_64.sh -b -f -p /anaconda'
test: test ! -d /anaconda
02_create_home:
command: 'mkdir -p /home/wsgi'
03_conda_activate_installation:
command: 'source ~/.bashrc'
wsgi.py:
sys.path.append('/anaconda/lib/python3.7/site-packages')
However when I add the 04_conda_install_pythonocc command below to the continuation of this .config file, I got command failed error.
04_conda_install_pythonocc:
command: 'conda install -c dlr-sc pythonocc-core=7.4.0'
I ssh into the instance for checking. I saw the /anaconda folder has occured. When I checked with the conda --version command, I got the -bash: conda: command not found error.
Afterwards, I thought there might be a problem with the PATH and I edited the .config file as follows and I have deployed this .config file successfully.
commands:
00_download_conda:
command: 'wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh'
test: test ! -d /anaconda
01_install_conda:
command: 'bash Anaconda3-2020.02-Linux-x86_64.sh -b -f -p /anaconda'
test: test ! -d /anaconda
02_create_home:
command: 'mkdir -p /home/wsgi'
03_add_path:
command: 'export PATH=$PATH:$HOME/anaconda/bin'
04_conda_activate_installation:
command: 'source ~/.bashrc'
But when I add the conda_install_pythonocc command again to the continuation of this edited version of .config file, it failed again and I got command failed.
In manually, all the commands work but they don't work in my .config file.
How can I fix this issue and install package with conda?
I tried to replicated the issue on my sandbox account, and I successful installed conda using the following (simplified) config file on 64bit Amazon Linux 2 v3.0.3 running Python 3.7:
.ebextensions/60_anaconda.config
commands:
00_download_conda:
command: 'wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh'
01_install_conda:
command: 'bash Anaconda3-2020.02-Linux-x86_64.sh -b -f -p /anaconda'
05_conda_install:
command: '/anaconda/bin/conda install -y -c dlr-sc pythonocc-core=7.4.0'
Note the use off absolute path /anaconda/bin/conda and -y to not ask for manual confirmations. I only verified installation procedure, not how to use it afterwards (e.g. not how to use it in python application). Thus you will probably need to adjust it to your needs.
The EB log file showing successful installation is also provided for your reference (shortened for simplicity):
/var/log/cfn-init-cmd.log

How do I run docker on AWS?

I have an aws code pipeline which currently successfully deploys code to my EC2 instances.
I have a Docker image that has the necessary setup to run my code, Dockerfile provided below. When I run docker run -t it just loads up an interactive shell on my docker but then hangs on any command (eg: ls)
Any advice?
FROM continuumio/anaconda2
RUN apt-get install git
ENV PYTHONPATH /app/phdcode/panaxeaA1
# setting up venv
RUN conda create --name panaxea -y
RUN /bin/bash -c "source activate panaxea"
# Installing necessary packages
RUN conda install -c guyer pysparse
RUN conda install -c conda-forge pympler
RUN pip install pysparse
RUN git clone https://github.com/usnistgov/fipy.git
RUN cd fipy && python setup.py install
RUN cd ~
WORKDIR /app
COPY . /app
RUN cd panaxeaA1/models/alpha04c/launchers
RUN echo "launching..."
CMD python launcher_260818_aws.py
docker run -t simply starts a docker container with a pseuodo-tty connection to the container's stdin. However, just running this command does not establish an interactive shell to the container. You will need this to be able to have run commands within your container.
You need to also append the -i command line flag along with the shell you wish to use. For example, docker run -it IMAGE_NAME bash will launch a container from the image you provide using bash as your interactive shell. You can then run Bash commands as you normally would.
If you are looking for a simple way to run containers on EC2 instances in AWS, I highly recommend AWS EC2 Container Service (ECS) as an option. It is a very simple service for running containers that abstracts and manages much of the server level work involved in running containers.

Create a Jenkins Job to run JMeter tests on a remote EC2 instance

I have a Java application that creates and runs JMeter tests.
Those tests need to be run on a remote EC2 instance.
Is it possible to have some command in Jenkins (which is on a separate AWS machine) to clone a git project to a remote EC2 instance? And run the flow there?
I will appreciate any thoughts and ideas!
So, here is my solution:
in Jenkins in Build section add 'Execute shell' step and do scp there for pom.xml and src folder from the Jenkins workspace to ec2 instance tmp folder
in my case it looks like this:
scp -i ../../../jobs/utilities/keys/.pem pom.xml ec2-user#ec2-00-000-00.compute.amazonaws.com:/tmp
scp -i ../../../jobs/utilities/keys/.pem -r src ec2-user#ec2-00-000-00.compute.amazonaws.com:/tmp
then add 'Send files or execute command over SSH' step and in the Exec command section put next:
sudo rm -rf ../../my_project_folder_name/
sudo mkdir ../../my_project_folder_name
cd ../../tmp
sudo cp pom.xml ../my_project_folder_name/
sudo cp -r src ../my_project_folder_name
cd ../my_project_folder_name
sudo mvn clean test
then add one more 'Execute shell' step to copy all the files from tag=rget folder to be able to use them for different reports:
scp -i ../../../jobs/utilities/keys/.pem -r ec2-user#ec2-00-000-00.compute.amazonaws.com:/my_project_folder_name/target .
That's it :)

Installing leiningen 2 on Ubuntu

I have followed the instructions here:
leiningen.org
To install from the lein script. I now have:
~/.lein/self-installs/leiningen-2.4.3-standalone.jar
How do I now run leiningen? The instructions are not clear.
On ubuntu, its quite easy. Download executable file, make it executable and place it in system path.
$ wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
$ chmod +x lein
$ sudo mv lein /usr/local/bin
You can also move it any directory which is in system path.
$ lein -v
Leiningen 2.6.1 on Java 1.8.0_77 Java HotSpot(TM) 64-Bit Server VM
Posting this as it might help other users.
Follow the install instructions.
Please make sure the leiningen script that the install instructions is on your executable PATH.
The script is the entry point to leiningen commands, so it's still needed after the downloads are complete.
It takes care of setting up environmental variables, paths and everything else required to run leiningen, so you can use
lein <command>
instead of
java -cp <whatever>:~/.lein/self-installs/leiningen-2.4.3-standalone.jar ... clojure.main -m leiningen.core.main <command>
I got the same doubt. Solved it. By following the instructions everything will be set for you. Next run the previously used script lein.sh in bin for creating projects as below.
suppose ~/bin/lein.sh is your script location ,then
$ ~/bin/lein.sh new test-project
$ ~/bin/lein.sh --help
It will create the project in your bin folder it self.If you wish to access that lein.sh globally then include it in $PATH.
If you are using a linux distribution you can just download the leiningen script and move it to your /bin folder. Once you've done that you can execute lein command and it will be installed for you.
So from your terminal you can run:
$ curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > ~/lein
to download lein script to your root path. Then you set it as executable and move to your /bin folder
$ chmod x+a lein
$ sudo mv ~/lein /bin
$ lein
After you run the command lein from anywhere on your terminal the lein script will install leininge for your and you'll be able to use it normally.