Remove of ADD in Dockerfile - dockerfile

I created a Dockerfile and use the ADD command to download an installer and execute it so I can prepare my docker container. But I can't find a delete counterpart. Am I missing something?
# Dockerfile
ADD https://../file.zip file.exe
.. do something with file.exe
Delete file.exe

Use RUN instead.
RUN rm file.exe

Related

build a docker image ros2 , when try tu run . install/setup.bash in dockerfile no works

i have the next problem:
i try to build a docker image with ros2, in which a code package is downloaded which will be built using the colcon build method.
but when I try to run last of. install / setup.bash doesn't work for me.
I already tried to put it in a script and copy it to the dockerfile but it didn't work
any ideas
here I leave the docker file
FROM osrf/ros:dashing-desktop
WORKDIR /home
COPY mobilidad.sh .
RUN bash mobilidad.sh
ENV ROS2_WS cleanmyway/test_ws
RUN mkdir -p ${ROS2_WS}/src/demo_py
COPY ./ ${ROS2_WS}/src/demo_py
WORKDIR ${ROS2_WS}
SHELL ["/bin/bash", "-c"]
RUN colcon build
RUN . install/setup.bash
note: mobilidad.sh is a script that dowload de code from github, this works fine
I think I managed to find a solution,
building the dockerfile as follows:
FROM osrf/ros:dashing-desktop
WORKDIR /home
COPY mobilidad.sh .
RUN bash mobilidad.sh
ENV ROS2_WS cleanmyway/test_ws
RUN mkdir -p ${ROS2_WS}
WORKDIR ${ROS2_WS}
RUN colcon build
RUN echo "source install/setup.bash" >> /opt/ros/dashing/setup.bash
and when i run the ros2 command works fine
but anyway thanks for the help. :)
note: i'm not sure if the better form but works for me

How to add a new group and user to that group in Photon OS

Creating a Docker image from vmware/photon:2.0
I want to run the application inside that container as a user different than root.
So, trying to create a new group and add user to it by following command:
groupadd -r new-group && useradd -r -g new-group new-user
It throws:
bash: groupadd: command not found
How can I achieve this?
You can install "shadow" package to be able to add groups/users.
tdnf -y install shadow
this is not necessary with Photon:3.0. all the prerequisite tools are ready. That could be because I installed a dep package or was just there.

Modify python file which was installed using pip inside an Docker image

I installed a python module called requests-aws4auth in docker using RUN pip install requests-aws4auth
Now I want to modify it by going into cd /opt/conda/lib/python2.7/site-packages/requests_aws4auth/ and commenting a line in aws4auth.py file. I already installed vim while building the docker.
Is it possible to do this while building the dockerfile? If yes, then can some one help me out.
I could do it by using sudo docker run -i -t image_name /bin/bash and modifying the file, but this will create a container. Now, is there any way to push the container back to the image.
There are two ways to do this:
Add some sed command that comments the line in the file after pip install command in dockerfile something like this -
RUN pip install requests-aws4auth
RUN sed -e '/BBB/ s/^#*/#/' -i file #some logic to comment the line
Build the docker image and use it.
If option-1 didn't seems to help try committing the container.
docker run the container do docker exec and comment the line in file. Now commit the container docker commit <conatainer-id> <some custom image name> https://docs.docker.com/engine/reference/commandline/commit/
Now use this custom image.

Compiling a file leaves files in my home directory when doing vagrant provision

I am using Vagrant to setup a linux box. I need to add a file I compiled to the system and I do so using the following commands -
sudo git clone https://github.com/thewtex/tmux-mem-cpu-load.git /tmp/tmuxcpu
sudo cmake /tmp/tmuxcpu
sudo make clean /tmp/tmuxcpu
sudo make install clean /tmp/tmuxcpu
However, this leaves tons of files including a makefile, config files, and other garbage inside the /home/vagrant/ folder. How do I make and install from tmp without littering the home directory with garbage?
The above commands work, but it leaves tons of files in the /home/vagrant folder that I don't want there. Is it possible to cmake, make, and make install without leaving 'trash'?
I have solved my issue with the help of Etan Reisner and reinierpost.
## CPU LOAD
sudo git clone https://github.com/thewtex/tmux-mem-cpu-load.git /tmp/tmuxcpu
sudo sh -c "cd /tmp/tmuxcpu && sudo cmake . && sudo make && sudo make install";
My install script now uses the above commands and this has resolved my issue. By keeping the files in /tmp, they are removed the moment I reboot the box. I am using this technique for several other items during the vagrant setup now and it works perfectly. This has solved numerous issues for me.

Running a Docker image command in a mounted folder

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.