i’m new to Docker and i have a question. I want to create a web site that will communicate with a docker container to make a certain process and get from that container a certain file back to give to the user of the web site. What are the steps to create this connection? I have the docker image ready but can’t seem to understand how is it possible to make this whole project viable. thanks you in advance.
Hm, I am not sure if I understood you correctly, but let me give you an common example.
You have two docker container running. One for nginx and another for php…
The nginx image will expose 80/tcp
The phpimage will expose 9000/tcp
Then on runyou’ll have to link both using their names…
docker run -d -n my_php <your-php-image>
docker run -d -p 80:80 -n my_nginx --link my_php <your-nginx-image>
What this does:
Both docker images are prepared to expose ports to the “outer” world. Why “outer”: well as you can see in the runstatement, only the webserver maps his ports to the hosts port, and so (if your firewall is set properly) to the real “outer” world. The php-container only expose this to the host and “inner” network (the docker subnet).
The magic is happening in --link my_php of the webserver …This will create an entry in /etc/hosts with the name given in -n my_php and than it will send all incoming requests (*.php) to port 9000 of my_php if you set this up in /etc/nginx/nginx.confor any vhost-config.
Firstly , thanks for the answer vir2I. Yes that’s what i was looking for. So after i do this when i use the web site it will link to the php image and run the commands i want then?
I’m not sure what you mean with ‘…i use the web site it will link’…
Your website (a bunch of text-documents and images) is stored in a folder of your webserver. The webserver is linked to the app-server (i .e php image). Each php statement ( marked with <?php and ?>) will then be send through port 9000 (if correctly setup in nginx.conf) to you app server. The return-value then can be displayed on your website.
I’m sorry. allow me to make things a bit more clear. I want to use a web site (docker image1) to send some files to another docker image (image2 running cordova in ubuntu) where a certain process is performed and a certain file is returned to the website (image1). I thought that if i used the website and pressed a certain button for example it would connect to the image2 and run some commands…that’s what i meant with …i use the website it will link…
for the cordova image i use the public image webratio/cordova from hub.cocker.com without any changes at all. I get the image running as container with
$ docker run -it webratio/cordova bash
For the wesite the Dockerfile is:
FROM nginx:alpine (official nginx)
COPY . /usr/share/nginx/html
where i have my html page at that directory
and i run
$ docker run -d -p 4000:80 nginx:myweb
to see the web page.
sorry i’m new so i can’t create .yml file successfully.
But in short: With compose you can run multiple container at once. you have one config file where you can setup your system. Its quit easy, don’t worry …