If I had understood correctly:
We can use a docker image of something instead of installing it.
I don't want to install openCV.
So I install the image :
docker pull spmallick/opencv-docker:opencv
I have a really simple cpp file which use openCV.
What should i do now to compile my file with this image.
in the terminal run
docker run -it --name myopencv spmallick/opencv-docker:opencv
open new terminal and copy your cpp file to the running container. for example i copy the file 1.cpp to tmp folder to myopencv container.
docker cp .\1.cpp myopencv:/tmp
return to the running container and run g++ <filename.cpp>
** the image you pulled already has all build-essential installed
Related
I would like to build a custom Docker file. I start with Ubuntu
FROM ubuntu
But I would also like to add buildpack-deps:stretch
I understand that I am only allowed to use FROM once, so short of copying the contents of buildpack-deps:stretch into my Docker file, how do I add it to my Docker file?
AFAIK, simply "including" another Dockerfile does not work. But, you actually are allowed to use multiple FROM statements, if you use multistage builds (cf. the Docker docs).
For example, you could do something like this:
FROM buildpack-deps:stretch AS build
RUN echo "hello world!" > /tmp/foo
FROM ubuntu
COPY --from=build /tmp/foo .
CMD ["cat", "foo"]
Running docker build --tag foo . && docker run --rm foo results in hello world!. You could replace the first RUN statement with the compilation of something or whatever you are planning to do.
There are more ways for using multistage builds, e.g. using FROM build in our example directly.
i am trying to run a cpp application within docker.After i have built the executable and created the Dockerfile , i can not run it inside docker for some reason:
main.cpp
#include<iostream>
#include<chrono>
#include<thread>
#include<string>
#include <unistd.h>
int main(int argc,char *argv[])
{
std::cout<<"Started daemon..."<<std::endl;
std::string hostString(argv[1]);
std::cout<<"HostName:"<<hostString<<std::endl;
std::cout<<"Port:"<<std::stoi(argv[2])<<std::endl;
int i=0;
while(true){
std::cout<<"Iterations:"<<i++<<std::endl;
std::this_thread::sleep_for (std::chrono::seconds(1));
if(i++>10000) i=0;
}
return 0;
}
Dockerfile
FROM ubuntu:latest
RUN mkdir -p /home/dockerc
COPY . /home/dockerc
ENTRYPOINT ["/home/dockerc/main","127.0.0.1","8350"]
dockerc folder
main.cpp
main.exe
Dockerfile
I run the following:
g++ main main.cpp
docker build app .
docker images (it shows that app image is created)
docker run app
The build is succesfull but when i hit the run it looks like it blocks.It just does not continue.
What is wrong?Could someone help me ?I am new to docker.
P.S After waiting out for like 10 minutes i get long error message that begins with the following:
$ docker run cpapp
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: container a575e463f193dbc475aab78c1810486e23981a50c 0b731f9c891c4143d0ed5b3 encountered an error during CreateProcess: failure in a Windows system call: The compute system exited unexpecte dly. (0xc0370106)
You should put the complete path in the ENTRYPOINT and add the parameters to your program.
This Dockerfile does the job:
FROM ubuntu:latest
RUN mkdir -p /home/dockerc
COPY . /home/dockerc
ENTRYPOINT ["/home/dockerc/main", "hostname", "8000"]
replacing hostname and 8000 with the hostname and port that you need.
Edit
I tested your program in Linux, and to make it run I had to:
1) compile for c++11 (because of chrono)
2) add -t to build the docker app
This is the complete list of commands to run:
g++ -o main main.cpp -std=c++11
docker build -t app .
docker run app
and this is the output:
replace your RUN cd... by a WORKDIR ...
your cd does not what you expect in this context, and is forgotten at the next line
you can also remove the RUN cd... line and put the whole path in the
ENTRYPOINT
line
I'm facing an strange problem with PIL. Whenever I am compiling the following code with python everything is ok:
from PIL import Image
file=Image.open("si.jpg")
file2=file.convert("L")
pix = file2.load()
print pix
colsize,rowsize=file2.size
for i in range(rowsize):
for j in range(colsize):
if pix[j,i]>250:
pix[j,i]=250
file2.save("ci2.pgm")
But when I compile the above code in SageMath Notebook, it gives an error “IOError: decoder jpeg not available”. Here is the scrrenshot :
I have found a similar problem here, but these solution does not work for me. My OS is Ubuntu 16.04 (32bit).
The image link :)
I want to get solution for SageMath. How do I solve this issue?
It seems your version of the Python package "Pillow"
(the Python Image Library) is missing the decoder for jpg.
To install it, quit Sage, and in a terminal, run the following:
$ sudo apt-get install libjpeg-dev
$ sage --pip install --no-cache-dir -I pillow
Then restart Sage and try running your code again.
I've got a Dockerfile I'm trying to build using the following code:
docker_image 'wafflehouse' do
source '/root/dockerimages/CentOS'
action :build_if_missing
read_timeout 6000
write_timeout 6000
end
Using test kitchen the builds fail:
Error executing action `build_if_missing` on resource 'docker_image[wafflehouse]'
No such image: sha256:4eda692c08e0a065cg91d74e82ffxxxxxxxx07b4341ad61fa61771cc4659af60
Docker::Error::NotFoundError
If I reference the Dockerfile directly in the code:
docker_image 'wafflehouse' do
source '/root/dockerimages/CentOS/Dockerfile'
action :build_if_missing
read_timeout 6000
write_timeout 6000
end
The build fails to find the files that are referenced in the Dockerfile to copy:
FROM centos
COPY wafflehouse.repo /etc/yum.repos.d
COPY wafflehouse-artifacts.repo /etc/yum.repos.d
COPY wafflehouse-snapshot-artifacts.repo /etc/yum.repos.d
RUN yum install -y net-tools
CMD ["bash"]
The files are in the same directory as the Dockerfile. Any ideas on either of these?
I believe you have a problem with the dockerfile instead of Chef.
You should keep in mind that you are providing a relative path to the source of the files you want to copy.
In order to fix this, try using absolute paths for source and target paths, something like:
FROM centos
COPY /root/dockerimages/CentOS/wafflehouse.repo /etc/yum.repos.d/wafflehouse.repo
COPY /root/dockerimages/CentOS/wafflehouse-artifacts.repo /etc/yum.repos.d/wafflehouse-artifacts.repo
COPY /root/dockerimages/CentOS/wafflehouse-snapshot-artifacts.repo /etc/yum.repos.d/wafflehouse-snapshot-artifacts.repo
RUN yum install -y net-tools
CMD ["bash"]
My environment is Linux 11.04
When I want to install Qt SDK
I download the SDK:qt-creator-linux-x86_64-opensource-2.5.2.bin
I move this file to /opt
and then
chmod u+x qt-creator-linux-x86_64-opensource-2.5.2.bin
./qt-creator-linux-x86_64-opensource-2.5.2.bin
but it shows that: cannot execute binary file
I think whether if it is because my Ubuntu is belong to 32-bit architecture
so I download qt-creator-linux-x86-opensource-2.5.2.bin
also move it to /opt file
and give the command:
chmod u+x qt-creator-linux-x86-opensource-2.5.2.bin
./qt-creator-linux-x86-opensource-2.5.2.bin
The same message still shows.
I give another command:
sudo ./qt-creator-linux-x86-opensource-2.5.2.bin
but it shows that Syntax error: ")" unexpected
how can I resolve this problem?