Communication between podman containers without root - docker

I am trying to deploy a web app with two podman containers. One is running gunicorn and the other runs a web server as a reverse proxy.
However, the communication between the containers is only successfull if I run them on the host with root. Is there a way around this?
Here is an example without root (which returns an empty IP Address):
$ podman run -dt --name test --rm -p 8000:8000 python:3.9 python -m http.server
$ podman container inspect test | grep IPAddress
"IPAddress": "",
With root, it is possible to do:
$ sudo podman run -dt --name test --rm -p 8000:8000 python:3.9 python -m http.server
$ sudo podman container inspect test | grep IPAddress
"IPAddress": "10.88.0.11",
"IPAddress": "10.88.0.11",
$ cat Dockerfile
FROM caddy:2
COPY Caddyfile /etc/caddy/Caddyfile
$ cat Caddyfile
:8001 {
reverse_proxy * 10.88.0.11:8000
}
$ sudo podman build . -t revproxy
$ sudo podman run -dt --rm -p 8001:8001 revproxy
and the proxy is working successfully on port 8001.

The two containers have to be in the same pod or the same network.
Using a pod, it is possible to do the following:
$ podman pod create -n test
$ podman run --rm --pod test python:3 python3 -m http.server
and in another shell:
$ podman run --rm --pod test python:3 curl localhost:8000

Related

How to create a Debian docker container that can run docker containers?

I need a Debian container that can run containers itself (and has access to systemd). Following this post, I have tried to run
docker run -v /var/run/docker.sock:/var/run/docker.sock --name debian-buster-slim -h 10-slim -e LANG=C.UTF-8 -it debian:10-slim /bin/bash -l
but the container cannot run docker containers. What am I doing wrong?

Unoconv call (openoffice) from other container

I am new in linux and docker. I need to convert odt files to pdf from php container. I use php-5.6-apache and https://github.com/xiaojun207/openoffice4-daemon:
sudo docker build --pull
-t xiaojun207/openoffice4-daemon
–build-arg OO_VERSION=4.1.7 .
sudo docker run -d --restart unless-stopped
-u 123456
–name soffice
–net my-network
-p 8100:8100
-v /data/output-odt:/pdfs/:rw
xiaojun207/openoffice4-daemon:latest
sample of openoffice4-daemon works well from host:
sudo docker run
-v /var/output-odt:/pdfs:rw
xiaojun207/openoffice4-daemon
–net my-network
unoconv --connection ‘socket,host=127.0.0.1,port=8100,tcpNoDelay=1;urp;StarOffice.ComponentContext’
-f pdf /pdfs/test.odt
But I need to execute it from my php container. docker run is not possible from other container. How can I do it? Thanks

How to use docker to run sqli-labs(a web application) on Windows?

I try to use Docker to run sqli-labs, I use the command:
docker pull acgpiano/sqli-labs
to pull the images, and after I use the command:
docker run -dt --name sqli -p 80:80 --rm acgpiano/sqli-labs
I visit the http://localhost, but my browser shows me 404..
here is the screenshot:
enter image description here
enter image description here
Why I can not get the right page?
Because the page is not accessible on your machines localhost but on your containers localhost.
You can access it if you go to localhost inside your container or on your machines IP.
EDIT:
How to access localhost inside the container:
# I ran the same commands as you
docker pull acgpiano/sqli-labs
docker run -dt --name sqli -p 80:80 --rm acgpiano/sqli-labs
# First get the container id with
docker ps -a
# I got this output:
# CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# d91384617370 acgpiano/sqli-labs "/run.sh" 3 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp, 3306/tcp sqli
# Then execute bash command as root for this container id
docker exec -it -u root d91384617370 bash
# Inside the container update apt-get and get curl (or wget)
apt-get update -y
apt-get install curl -y
# Go to localhost - the page will be printed in your terminal
curl localhost
How to access it in windows 10 (tested with Docker version 18.03.1-ce, build 9ee9f40), I'm using powershell and docker for windows
docker pull acgpiano/sqli-labs
docker run -dt --name sqli -p 80:80 --rm acgpiano/sqli-labs
# In powershell get the hostname - copy it to your browser - http://your_hostname or just your_hostname
hostname
# Or run ipconfig to find your IP - copy it to your browser http://your_ip or your_ip
ipconfig | findstr [0-9].\.
I would also recommend this example from the docs, great way to get started.

How to import CSV data to table through Docker container clickhouse-client

I'm using Docker for Windows:
Docker version 18.03.1-ce-win64
Docker Engine 18.03.1-ce
ClickHouse client version 1.1.54380
ClickHouse server version 1.1.54380
For exporting data from table into CSV format I am using the command:
Now run clickhouse-client container for export
$ docker run -it --rm --link clickhouse-server:clickhouse-client yandex/clickhouse-client -m --query="select * from default.table1 FORMAT CSV" > C:/Users/sony/Desktop/table1_data.csv --host clickhouse-server
NOTE: The above command works perfectly.
Now run clickhouse-client container for import
$ docker run -it --rm --link clickhouse-server:clickhouse-client yandex/clickhouse-client -m -c "cat C:/Users/sony/Desktop/table1_data.csv | clickhouse-client --host clickhouse-server --query='INSERT INTO default.table1 FORMAT CSV' "
Could you please tell me what I am doing wrong when importing?
Thanks in advance.
I think you should mount the csv file inside the container first. To mount the file you should add -v C:/Users/sony/Desktop/table1_data.csv :~/table1_data.csv option on your docker command. So your docker run command should be like this:
$ docker run -it --rm --link clickhouse-server:clickhouse-client yandex/clickhouse-client -m -v C:/Users/sony/Desktop/table1_data.csv:~/table1_data.csv -c "cat ~/table1_data.csv | clickhouse-client --host clickhouse-server --query='INSERT INTO default.table1 FORMAT CSV'"
Edit
My bad. Mounting inside the file wont work. Try this instead:
cat path_to_file/table1_data.csv | docker run -i --rm --link clickhouse-server:clickhouse-client yandex/clickhouse-client -m --host clickhouse-server --query="INSERT INTO default.table1 FORMAT CSV"
Already tried on linux, and it works. Since cat not works on Windows, I found type has same functionality, honestly haven't try it:
`type C:/Users/sony/Desktop/table1_data.csv | docker run -i --rm --link clickhouse-server:clickhouse-client yandex/clickhouse-client -m --host clickhouse-server --query="INSERT INTO default.table1 FORMAT CSV"`
Hope it works.

Cannot access tomcat8 server running in docker container from host machine

I am trying to connect to a web app running on tomcat8 in a docker container.
I am able to access it from within the container doing lynx http://localhost:8080/myapp, but when I try to access it from the host I only get HTTP request sent; waiting for response.
I am exposing port 8080 in the Dockerfile, I am using sudo docker inspect mycontainer | grep IPAddress to get the ip address of the container.
The command I am using to run the docker container is this:
sudo docker run -ti --name myapp --link mysql1:mysql1 --link rabbitmq1:rabbitmq1 -e "MYSQL_HOST=mysql1" -e "MYSQL_USER=myuser" -e "MYSQL_PASSWORD=mysqlpassword" -e "MYSQL_USERNAME=mysqlusername" -e "MYSQL_ROOT_PASSWORD=rootpassword" -e "RABBITMQ_SERVER_ADDRESS=rabbitmq1" -e "MY_WEB_ENVIRONMENT_ID=qa" -e "MY_WEB_TENANT_ID=tenant1" -p "8080:8080" -d localhost:5000/myapp:latest
My Dockerfile:
FROM localhost:5000/web_base:latest
MAINTAINER "Me" <me#my_company.com>
#Install mysql client
RUN yum -y install mysql
#Add Run shell script
ADD run.sh /home/ec2-user/run.sh
RUN chmod +x /home/ec2-user/run.sh
EXPOSE 8080
ENTRYPOINT ["/bin/bash"]
CMD ["/home/ec2-user/run.sh"]
My run.sh:
sudo tomcat8 start && sudo tail -f /var/log/tomcat8/catalina.out
Any ideas why I can access it from within the container but not from the host?
Thanks
What does your docker run command look like? You still need to do -p 8080:8080. Expose in the dockerfile only exposes it for linked containers not to the host vm.
I am able to access the tomcat8 server from the host now. The problem was here:
sudo tomcat8 start && sudo tail -f /var/log/tomcat8/catalina.out
Tomcat8 must be started as a service instead:
sudo service tomcat8 start && sudo tail -f /var/log/tomcat8/catalina.out
Hit given command to find IP address of docker-machine
$ docker-machine ls
The output will be like :
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default * virtualbox Running tcp://192.168.99.100:2376 v1.10.3
Now run your application from host machine as : http://192.168.99.100:8080/myapp

Resources