Committing an interactive container in docker - bash

I am trying to install the vim editor on bash in the centOS container in docker. However, as soon as I am exiting the container, I am losing my progress. Is there a way where I can commit the container after I am done with downloading the editor?
This is what I am doing:
user#personal-pc:~/Desktop$ sudo docker run -i -t centos /bin/bash
[root#9c0f428c4907 /]# yum install vim
After the installation is done, the editor works perfectly. However, when I end this running session, and run bash again, then the editor does not exist.
[root#d17ae0e8bf85 /]# vim abc.txt
bash: vim: command not found
How do I go about committing the previous container where the editor was installed?

when I end this running session
-> so now, you do docker commit 1234 mycontainer , if you start a new interactive session, you lose what you did before

commit the container 9c0f428c4907 with a new name.(After installing vim)
Eg: docker commit 9c0f428c4907 centos_viminstalled
Now run this cnetos_viminstalled image in a container
docker run -i -t cnetos_viminstalled /bin/bash
You will be able to see that vim is installed in this new image centos_viminstalled

Related

Docker is not running when run curl command to create new laravel project

I just start learning laravel, and follow the tutorial from https://laravel.com/docs/8.x/installation "Getting started on Windows" .
I manage to install Docker Desktop and COnfigured to use WSL2 Backend.
When I run the command curl -s https://laravel.build/example-app | bash to create laravel application directory from cmd, this warning come out Docker is not running.
I run curl using command prompt. (cmd).
Update:
So, I run the command in Windows Terminal:.
PS E:\Play> curl -s https://laravel.build/example-app | bash
Here is the response I get:
cmdlet Invoke-WebRequest at command pipeline position 1
Supply values for the following parameters:
Uri:
Any Idea what to do?
Try to explicitly enable integration with your distro in Docker settings:
After that relaunch your WSL2 terminal & try again. That should help.
You can also open https://laravel.build/example-app in a browser & check what commands the script is running: and run them manually to check the output for any errors.
For those who are using Ubuntu or Debian can check this guide out on how to install and configure Docker.
sudo snap install docker
sudo usermod -aG docker $(whoami)
sudo chmod 666 /var/run/docker.sock
You need to install a linux distro, and then in Windows Terminal create a new tab for the linux distro and run the command there, not in a windows powershell tab.
Make sure that you are running curl command on your distro. Use Windows Terminal app and open a new tab as WSL2 (your distro).
sudo chmod 666 /var/run/docker.sock
I guess you are using ubuntu or debian.
chmod will do the trick here.

Unable to open remote display on Mac when running Docker

I have a Dockerfile written as below:
FROM joesan/raspi_opencv_3:latest
RUN apt-get update
RUN sudo apt-get install --no-install-recommends xserver-xorg
RUN sudo apt-get install --no-install-recommends xinit
RUN apt-get install -qqy x11-apps
RUN mkdir -p /raspi_motion_detection/project
WORKDIR /raspi_motion_detection/project
COPY ./ $WORKDIR/
COPY ./requirements.txt $WORKDIR/
ADD . $WORKDIR
CMD xclock
I have a Raspberry Pi to which I ssh from my Mac (running High Sierra).
Here is what I do:
I ssh into the RaspPi from my Mac
I execute the docker command using:
docker run -ti --device=/dev/vcsm \
--device=/dev/vchiq \
-e DISPLAY=$DISPLAY:0 \
-e XAUTHORITY=/.Xauthority \
-v /tmp/.X11-unix:/tmp/.X11-unix \
joesan/motion_detector
I get an error message as below:
Error: Can't open display: localhost:11.0:0
But when I just run xclock directly on the ssh terminal, I can see that the xclock window opens up.
So I could not understand why running xclock from within a Docker container would prevent the display port being opened? Any reasons? I also came across this post here and followed what has been described there, but i could not get it to work!
https://medium.com/#dimitris.kapanidis/running-gui-apps-in-docker-containers-3bd25efa862a
A bit simplified: Each docker container runs inside the docker daemon, which basically provides a stripped down os to each container. That os has no window manager.
That is why the command xclock inside a docker container exits with an error.
When you connect via ssh to your raspberry pi and call xclock it is executed inside the raspberry's os (propably raspian), which has a running window manager.
Ok! So I thinkI found the solution to my problem! Here is what I did!
Re-installed Raspberry Stretch Lite on my SD card. The old one seems to have gotten some stale files! You can skip this step, but for me there was some corrupt files on the old installation, so I decided to get a fresh install!
On my Raspberry Pi, run the following command:
xauth list
I copy the cookie locally to a text editor as I need it later!
Removed the xclock command from the Dockerfile that I originally had!
Build the Dockerfile using the following command:
docker run -it --net=host --device=/dev/vcsm --device=/dev/vchiq -e
DISPLAY -v /tmp/.X11-unix joesan/motion_detector bash
Notice that I'm running a bash command to my Docker run so that I can get a basj prompt from the running image!
The result of step 3 would give me a bash prompt from the container that I just ran at step 3
I need to now install xauth in the image
apt-get install xauth
I then add the xauth cookie from step 0
It is after this Bang! I got what I want!

Run a docker image on Windows results in "oci runtime error: exec: "bash": executable file not found in $PATH."

I'm running Docker on Windows ("Docker Toolbox", not "Docker for Windows").
I've built an image with a rails app inside. It works properly on my Mac OS but stucks on production on Windows.
Using Docker 1.12 and docker-machine 0.8.0 on both machines.
When I create a machine and try to run the container from image, I do:
docker run -it myRepo:myTag bash
which opens me a interactive terminal on Mac OS, but Windows 7 and Windows Server 2011 are both responding with:
"Error response from daemon: oci runtime error: exec: "bash":
executable file not found in $PATH."
I use the MINGW64 shell via the Docker Quickstart Terminal but the old cmd.exe returns the same.
Can anybody help me with this issue? I've tried several hours to find a solution but there are too few answers for Windows.
Thank you in advance!
I also use Windows 7 with MINGW64. Here is what I get using nginx as example:
$docker run -it nginx bash
cannot enable tty mode on non tty input
I don't think you can open a tty using MINGW64.
You can try:
$docker run -i nginx bash
ls
bin
...
You will so no prompt or any indication you are inside the container. Just run ls and it should work inside your container.
Another option is to try to use winpty for the tty:
$ winpty docker run -it myRepo:myTag bash
root#644f59e6f818:/#
Have you tried?
$ winpty docker run -it myRepo:myTag /bin/bash
I haven't got the problem you are mentioning but I have seen it before when I was mapping volumes.
If you are mapping volumes using MINGW64, you will need to add an extra / before the local mapping. For example:
docker run -p 8080:80 -v "/$PWD":/var/share/nginx/html nginx
Let me know your findings.

How can I keep a docker debian container open?

I want to use a debian Docker container to test something, and by this I mean execute some commands in the debian bash console. I tried downloading the image using docker pull debian and then running it using docker run debian, but I get no output. What am I doing wrong? Shouldn't the docker container stay open until I close it?
You need to explicitly run bash:
docker run -it debian /bin/bash
The -i means "run interactively", and -t means "allocate a pseudo-tty".
A good place to read a bit more is the section Running an interactive shell in the Quickstart documentation.

How to edit files inside a docker container?

I cloned the docker-sinatra from Github (https://github.com/tcnksm-sample/docker-sinatra).
Built the image using:
sudo docker build -t sinatra .
Run the container:
sudo docker run -d -p 4567:4567 sinatra
Everything works fine. Now I want to change the content of the application file inside the container. I tried to attach the container and open the application file with vi and edit it but it's kinda hectic and doesn't work.
Is there a better way to edit files inside the container or a better tool instead of vi that I can use inside the container?
Do you want to permanently change the contents of the app file? Then change it before you do the docker build.
I just installed nano in the docker container so I could use it instead of vi to change to application file.
vi is behaving weirdly when I tried to edit the application file inside the container I don't know if it just me.
The docker-sinatra docker container was built from a ubuntu base.
Thus when inside the container, you can install vi/vim by issuing command
sudo apt-get install vi
sudo apt-get install vim

Resources