How to edit files inside a docker container? - ruby

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

Related

Docker setup on WSL for a Laravel website

I have entered into the WSL terminal the following command:
docker compose build --no-cache && docker compose up
This is what happened:
I have not downloaded anything outside of Docker on this computer and I have cloned this "backend" from the repository.
I have no experience in Docker or Laravel.
What methods should I start with to fix this?
The option -g in the groupadd command needs to be numerical, you can't use use the word sail.
See Ubuntu's documentation about that command and option here.

Cannot create file with Jupyter Notebook running in Docker in Windows 10

I have installed Docker Toolbox for Windows v 18.09 in Windows 10 Version 10.0.19041 Build 19041 and am trying to run a docker container to run Jupiter Notebook with Pyspark.
I am using Windows Powershell to execute docker commands
docker run hello-world works fine so I can assume that Dockers has been installed correctly. Infact, I had go down to Toolbox v 18.09 before I could get hello world to work.
i use the following command to run the pyspark container
docker run -it --rm -p 8888:8888 --volume=//C/Users/prith/pydev://home/jovyan/work jupyter/pyspark-notebook
from the C:/Users/prith/pydev directory that is mapped to the work directory of the container. The // is slash is required because i am working with Windows. the notebook shows up in http://192.168.99.100:8888 as expected and I can login with the token.
Then the problem starts when i try to create a new notebook or even a text file, I get a permission denied error. Evidently the container cannot write to 'some' directory. I have used Windows filesystem properties to give Everyone all privileges on this particular directory and have also run the Powershell in Adminstrtor mode ( to simulate Ubuntu sudo ..) but nothing works.
Interestingly, I can write into the directory located above the work directory in the container but then I cannot access files written into that directory from Windows because I have mapped my local windows directory to /home/jovyan/work
What do what i want? I want to create Jupyter notebooks in the container and save them in Windows
I know all this works like a charm in Linux-Ubuntu, but unfortunately I am stuck with Windows 10. Please help.
It looks you forgot to add the directory you're trying to mount to FILE SHARING.
Please, do right-click on docker icon (in system tray) -> Settings -> Resources -> FILE SHARING
Then, add your local directory.
Finally, if it doesn't work, try to mount volume with --volume="C:\Users\prith\pydev":/home/joyvan/work
this command seems to work
docker run -it --rm -p 8888:8888 --volume='/c/Users/Public/PyDev'://home/jovyan/work jupyter/pyspark-notebook start-notebook.sh --NotebookApp.token=''

Docker unable to process Dockerfile

I trying to create Dockerfile file from scratch on Windows7. However, currently have trouble on very first step. My Dockerfile is placed under C:\Users\Arturas\Docker\Jenkins. Virtual Box shared folder path on c:\Users and folder name on c/Users (defaults from boot2docker was not changed).
When I run (on git bash):
$ docker build --file Docker/Jenkins/ .
I get:
unable to process Dockerfile: read C:\Users\Arturas\Docker\Jenkins:
The handle is invalid.
Dockerfile content is just one line:
FROM jenkins
I just started learning Docker so my experience is very limited yet. However from tools like boot2docker I expect basic commands to work out of the box so I must be missing something.
Try instead:
cd /C/Users/Arturas/Docker/Jenkins
docker build -t myimage .
I assume here that you have a file named Dockerfile under the Jenkins folder.
The -f option of a docker build is for referencing the Dockerfile (if it is named differently for instance)
Don't forget to use the latest docker-machine (the 0.5.4 one: an auto-extractible exe docker-machine_windows-amd64.exe): it uses a VM named boot2docker.iso through VirtualBox.
Try to specify the "Dockerfile" name
$ docker build --file Docker/Jenkins/Dockerfile .

Dockerfile, how to create images ubuntu 14.04

Yesterday I've been asked about how to make a docker images with dockerfile
This time I want to add a question
If I want to make the OS ubuntu 14:04 on images docker, which it is installed, postgresql-9.3.10, install Java JDK 6, copy the file (significant location), and create a user on the images.
Whether I can combine of several dockerfile as needed for images? (dockerfile of postgresql, java, copyfile, and create a user so one dockerfile)
Example. I made one dockerfile "ubuntu"
which contains the command
top line
# Create dockerfile
# get OS ubuntu to images
FROM ubuntu: 14:04
# !!further adding a command on the following link, below the line per-dockerfile(intends command in dockerfile on the link)
# command on dockerfile postgresql-9.3
https://github.com/docker-library/postgres/blob/ed23320582f4ec5b0e5e35c99d98966dacbc6ed8/9.3/Dockerfile
# command on dockerfile java
https://github.com/docker-library/java/blob/master/openjdk-6-jdk/Dockerfile
# create a user on images ubuntu
RUN adduser myuser
# copy file/directory on images ubuntu
COPY /home/myuser/test /home/userimagedockerubuntu/test
# ?
CMD ["ubuntu:14.04"]
Please help me
No, you cannot combine multiple Dockerfile.
The best practice is to:
start from an imabe already included what you need, like this postgresql image already based on ubuntu.
That means that if your Dockerfile starts with:
FROM orchardup/postgresql
You would be building an image which already contains ubuntu and postgresql.
COPY or RUN what you need in your dockerfile, like for openjdk6:
RUN \
apt-get update && \
apt-get install -y openjdk-6-jdk && \
rm -rf /var/lib/apt/lists/*
ENV JAVA_HOME /usr/lib/jvm/java-6-openjdk-amd64
Finally, your default command should run the service you want:
# Set the default command to run when starting the container
CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]
But since the Dockerfile of orchardup/postgresql already contains a CMD, you don't even have to specify one: you will inherit from the CMD defined in your base image.
I think nesting multiple Dockerfiles is not possible due to the layer system. You may however outsource tasks into shell scripts and run those in your Dockerfile.
In your Dockerfile please fix the base image:
FROM ubuntu:14.04
Further your CMD is invalid. You may want to execute a bash with CMD ["bash"] that you can work with.
I would suggest you to start with the doc on Dockerfile as you clearly missed this and it contains all the answers to your questions, and even questions you don't even think to ask yet.

ADD Command for Docker Toolbox on Mac

I have Docker Toolbox installed on my Mac, but I'm having issues adding a file to a container during build. I'm using the ADD command in the Dockerfile. I can't seem to add any local files. I understand that Docker Toolbox uses VirtualBox under the hood, but I am not sure how to get those files into the VM to build the container. Is there a way I can do it that allows me to keep a clean OS-agnostic Dockerfile without any absolute paths?
Here is my Dockerfile. It's built from the Node.js container with some additional dependencies.
FROM node:4.2.2
RUN apt-get update
RUN apt-get install -y libvips-dev libgsf-1-dev libkrb5-dev
RUN apt-get clean
ADD app/ /app
RUN cd /app && npm install --production
RUN npm install forever -g
Turns out this does work, but only for my current directory. My Dockerfile and the files I wanted to add were not in the same directory. Moving the shell to the files I wanted, and then manually specifying the Dockerfile worked.
docker build -f my/other/Dockerfile .
Since docker will use a VirtualBox VM on Mac (with boot2docker or with docker-machine), it will use VirtualBox Guest Additions, which is there for the express purpose of using VirtualBox folder sharing.
Make sure to be in such a shared path, typically in /Users/....
If app/ is in /Users/path/to/app, then ADD should work.
You can mount other paths with boot2docker, but it can be problematic with docker machine (see issue 13).
Of course, for ADD app ... to work, you need to be in the parent folder of app/.
From docker ADD:
The <src> path must be inside the context of the build; you cannot ADD ../something /something

Resources