Podman mount host volume return 'Error: statfs: no such file or directory' in Mac OS - mount

Recently switched from Docker Desktop to Podman, everything work smoothly except when I want to mount host volume into container. e.g.
➜ ~ podman run --name nginx -v ~/bin/nginx/nginx.conf:/etc/nginx/nginx.conf:ro -d -p 8080:80 nginx
Error: statfs /Users/rb/bin/nginx/nginx.conf: no such file or directory
➜ ~ ls -lt ~/bin/nginx/nginx.conf
-rw-r--r-- 1 rb staff 490 Apr 23 14:31 /Users/rb/bin/nginx/nginx.conf
The host file ~/bin/nginx/nginx.conf do exist, so what's the problem here?

Had the same problem on MacOs.
I fixed it when used mount point not from the host machine itself, but from podman virtual machine.
So firstly i mounted the host volume to podman vm:
podman machine init -v $HOST_VOLUME:/mnt/$PODMAN_VM_VOLUME
And after that mounted PODMAN_VM_VOLUME to CONTAINER_VOLUME:
podman run -d -it --name test -v /mnt/$PODMAN_VM_VOLUME:/$CONTAINER_VOLUME

Related

podman ports connection refused after stopping and starting/restarting pod

I'm new to using podman and am trying to follow along with Richard Walker's tutorial for containerizing a django app (https://www.richardwalker.dev/django-podman.html)
It works fine until I try to stop and restart the pod. Then my host machine can no longer connect to ports (which were exposed when building the images and mapped when the pod was created).
The docs & guides suggest that it is a simple as issuing
podman pod stop ...
podman pod start ...
but this does not seem to work.
Would appreciate your help if you can see that I am missing something.
$ podman pod create -p 8000 -p 7000 -p 5432 -n cardpod
8553ad8fc0b14a849598a51c4ffcbffa9d6d094b96b542f0e432fc0d6dfd22ff
$ podman run --name deckofcards-prod-ctr --pod cardpod -d richardwalker.dev/deckofcards-prod-img
3dbf6f9ad043fe65492f0e15be642af92916ad9e09d941e1f96315343a8d2fae
$ curl http://127.0.0.1:7000/deck/
[{"suit":"clubs","face":"queen","value":10},{"suit":"spades","face":"four","value":4},{"suit":"hearts","face":"king","value":10},{"suit":"diamonds","face":"six","value":6},{"suit":"hearts","face":"two","value":2},{"suit":"diamonds","face":"ace","value":1},{"suit":"hearts","face":"eight","value":8},{"suit":"clubs","face":"three","value":3},{"suit":"spades","face":"five","value":5},{"suit":"clubs","face":"nine","value":9},{"suit":"spades","face":"nine","value":9},{"suit":"diamonds","face":"five","value":5},{"suit":"hearts","face":"nine","value":9},{"suit":"diamonds","face":"two","value":2},{"suit":"clubs","face":"king","value":10},{"suit":"diamonds","face":"eight","value":8},{"suit":"clubs","face":"ace","value":1},{"suit":"hearts","face":"three","value":3},{"suit":"spades","face":"jack","value":10},{"suit":"hearts","face":"ten","value":10},{"suit":"spades","face":"king","value":10},{"suit":"spades","face":"ace","value":1},{"suit":"spades","face":"ten","value":10},{"suit":"hearts","face":"five","value":5},{"suit":"hearts","face":"ace","value":1},{"suit":"clubs","face":"eight","value":8},{"suit":"hearts","face":"jack","value":10},{"suit":"diamonds","face":"queen","value":10},{"suit":"clubs","face":"ten","value":10},{"suit":"diamonds","face":"nine","value":9},{"suit":"clubs","face":"five","value":5},{"suit":"clubs","face":"jack","value":10},{"suit":"diamonds","face":"ten","value":10},{"suit":"hearts","face":"queen","value":10},{"suit":"diamonds","face":"seven","value":7},{"suit":"hearts","face":"seven","value":7},{"suit":"hearts","face":"six","value":6},{"suit":"spades","face":"two","value":2},{"suit":"clubs","face":"two","value":2},{"suit":"clubs","face":"seven","value":7},{"suit":"spades","face":"seven","value":7},{"suit":"clubs","face":"four","value":4},{"suit":"spades","face":"queen","value":10},{"suit":"diamonds","face":"king","value":10},{"suit":"spades","face":"six","value":6},{"suit":"diamonds","face":"jack","value":10},{"suit":"diamonds","face":"four","value":4},{"suit":"hearts","face":"four","value":4},{"suit":"clubs","face":"six","value":6},{"suit":"diamonds","face":"three","value":3},{"suit":"spades","face":"three","value":3},{"suit":"spades","face":"eight","value":8}]
$ podman pod stop cardpod
8553ad8fc0b14a849598a51c4ffcbffa9d6d094b96b542f0e432fc0d6dfd22ff
$ podman pod start cardpod
8553ad8fc0b14a849598a51c4ffcbffa9d6d094b96b542f0e432fc0d6dfd22ff
$ curl http://127.0.0.1:7000/deck/
curl: (7) Failed to connect to 127.0.0.1 port 7000: Connection refused
More Info:
I can see that the django servers are running by inspecting "podman logs <container_id>" and the mapped ports are still available from viewing "podman port <pod_id>"
dockerfile as per tutorial:
# FROM directive instructing base image to build upon
FROM python:3.7-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Create and change to working dir
RUN mkdir /code
WORKDIR /code
# Copy code
COPY /release/ /code/
# Install dependencies
COPY requirements.txt /code/
RUN pip install -r requirements.txt
# EXPOSE port 7000 to allow communication to/from server
EXPOSE 7000
# CMD specifies the command to execute to start the server running.
CMD python3 manage.py runserver 0.0.0.0:7000
podman: version 2.0.2
distro: ubuntu 18.04

My docker container isn't starting on localhost (0.0.0.0) on Docker for Windows (Native using Hyper-V)

I'm following Digital Ocean's tutorial on how to start a nginx docker container (Currently on Step 4). Currently this is their output:
$ docker run --name docker-nginx -p 80:80 -d nginx
d3ccb73a91985651ec61231bca9f9c716f0dec807e354a29eeef2144f883a01c
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b91f3ce26553 nginx "nginx -g 'daemon off" About a minute ago Up About a minute 0.0.0.0:80->80/tcp, 443/tcp docker-nginx
But when I run it, this is my output (noticed the different IP of the container):
C:\>docker run --name docker-nginx -p 80:80 -d nginx
d3ccb73a91985651ec61231bca9f9c716f0dec807e354a29eeef2144f883a01c
C:\>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d3ccb73a9198 nginx "nginx -g 'daemon off" 14 hours ago Up 2 seconds 10.0.75.2:80->80/tcp, 443/tcp docker-nginx
Why does this happen? And how can I get the same results as Digital Ocean's? (Getting the server to start on localhost)
Edit: I'm using Docker for windows (recently released) which apparently runs native using Hyper-V. My output for docker-machine ls is this:
C:\>docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
C:\>
But when I run it, this is my output (noticed the different IP of the
container)
Since this a Windows machine, I assume that you're using Docker Toolbox Docker for Windows. 10.0.75.2 is the IP of the boot2docker virtual machine.
If you are using Windows or Mac OS, you will need some form of virtualization in
order to run Docker. The IP you just saw is the IP of that lightweight virtual machine.
And how can I get the same results as Digital Ocean's? (Getting the
server to start on localhost)
Use a Linux distribution! Also you can enable Expose container ports on localhost in Docker For Windows Settings:
Despite you created the containers in your local machine. These are actually running on a different machine (a virtual machine)
First, check what is the IP of your docker machine (the virtual machine)
$docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
default * virtualbox Running tcp://192.168.99.100
Then run curl command (or open a browser) to view the default web site on your nginx web server inside the container
curl http://192.168.99.100:80
if you are using a virtual machine on windows:
docker-machine ip default
https://docs.docker.com/machine/concepts/
When I ran this command for the first time: docker run -d -p 80:80 --name docker-tutorial docker101tutorial
I got this error:
docker: Error response from daemon: Conflict. The container name
"/docker-tutorial" is already in use by container "LONG_CONTAINER_ID".
You have to remove (or rename) that container to be able to reuse that
name.
so, I tried to remove this container using: docker rm -f LONG_CONTAINER_ID
then I did: docker run -d -p 3080:80 --name docker-tutorial docker101tutorial
note 3080:80 instead of 80:80... Had I run this from the docker desktop, I would see this default option below:

Unable to connect to Docker Nginx build

I am trying to host a simple static site using the Docker Nginx Image from Dockerhub: https://registry.hub.docker.com/_/nginx/
A note on my setup, I am using boot2docker on OSX.
I have followed the instructions and even I cannot connect to the running container:
MacBook-Pro:LifeIT-war-games-frontend ryan$ docker build -t wargames-front-end .
Sending build context to Docker daemon 813.6 kB
Sending build context to Docker daemon
Step 0 : FROM nginx
---> 42a3cf88f3f0
Step 1 : COPY app /usr/share/nginx/html
---> Using cache
---> 61402e6eb300
Successfully built 61402e6eb300
MacBook-Pro:LifeIT-war-games-frontend ryan$ docker run --name wargames-front-end -d -p 8080:8080 wargames-front-end
9f7daa48a25bdc09e4398fed5d846dd0eb4ee234bcfe89744268bee3e5706e54
MacBook-Pro:LifeIT-war-games-frontend ryan$ curl localhost:8080
curl: (52) Empty reply from server
MacBook-Pro:LifeIT-war-games-frontend ryan$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9f7daa48a25b wargames-front-end:latest "nginx -g 'daemon of 3 minutes ago Up 3 minutes 80/tcp, 0.0.0.0:8080->8080/tcp, 443/tcp wargames-front-end
Instead of localhost, use boot2docker ip. First do boot2docker ip and use that ip:
<your-b2d-ip>:8080. Also you need to make sure you forwarded your port 8080 in VirtualBox for boot2docker.
Here is the way to connect nginx docker container service:
docker ps # confirm nginx is running, which you have done.
docker port wargames-front-end # get the ports, for example: 80/tcp, 0.0.0.0:8080->8080/tcp, 443/tcp
boot2docker ip # get the IP address, for example: 192.168.59.103
So now, you should be fine to connect to:
http://192.168.59.103:8080
https://192.168.59.103:8080
Here's how I got it to work.
docker kill wargames-front-end
docker rm wargames-front-end
docker run --name wargames-front-end -d -p 8080:80 wargames-front-end
Then I went to my virtualbox and setup these settings:

about docker link and container's /etc/hosts file

I am following the docker official doc"Linking Containers Together". At the bottom of this doc, on the container's /etc/hosts file, it defines ip address for both ends of a link.
$ sudo docker run -t -i --rm --link db:db training/webapp /bin/bash
root#aed84ee21bde:/opt/webapp# cat /etc/hosts
172.17.0.7 aed84ee21bde
. . .
172.17.0.5 db
And then, it says:
If you restart the source container, the linked containers /etc/hosts files will be automatically updated with the source container's new IP address, allowing linked communication to continue.
$ sudo docker restart db
db
$ sudo docker run -t -i --rm --link db:db training/webapp /bin/bash
root#aed84ee21bde:/opt/webapp# cat /etc/hosts
172.17.0.7 aed84ee21bde
. . .
172.17.0.9 db
I am wandering, what about the link created before container 'db' restart, the old recipient's /etc/hosts file still keep 'db' old ip, but after 'db' container's ip changed after it restarted, the /etc/hosts file lost its effect.
There is a known bug in docker that affects some versions of it #6350. Also some versions of docker has this problem when you are using link aliases. So if you upgrade your docker to latest version (currently 1.8.1) the problem can be solved.

lxc containers on another partition

I have created two containers(say TestOneContainer and TestTwoContainer) in ubuntu server using LXC. Now the lxc filesystem is in /home folder and two containers also use /home folder. I have created two partition(100 GB for TestOneContainer and 200 GB for TestTwoContainer) for those two containers while Ubuntu server OS installation. I want to mount TestOneContainer in 100 GB space and TestTwoContainer in 200 GB space. How can I do this?
I have tried these commands from this link
create and symlink two directories:
sudo mkdir /srv/lxclib /srv/lxccache
sudo rm -rf /var/lib/lxc /var/cache/lxc
sudo ln -s /srv/lxclib /var/lib/lxc
sudo ln -s /srv/lxccache /var/cache/lxc
or, using bind mounts:
sudo mkdir /srv/lxclib /srv/lxccache
sudo sed -i '$a \
/srv/lxclib /var/lib/lxc none defaults,bind 0 0 \
/srv/lxccache /var/cache/lxc none defaults,bind 0 0' /etc/fstab
sudo mount -a
But these commands are to mount lxc in different filesystem not TestOneContainer or TestTwoContainer.
suppose 100GB free space is under /mnt/sd1 and 200GB is under /mnt/sd2, and you want to mount them under /work in containers, use following commands to mount it to the containers:
#create mount point from host
sudo mkdir /var/lib/lxc/TestOneContainer/rootfs/work
sudo mkdir /var/lib/lxc/TestTwoContainer/rootfs/work
#mount them from host
sudo mount --bind /mnt/sd1/ /var/lib/lxc/TestOneContainer/rootfs/work
sudo mount --bind /mnt/sd2/ /var/lib/lxc/TestTwoContainer/rootfs/work
Then start the containers, and you will see /work with that big space with
df -h
You should read this LXC source, specifically to the section
Host Setup -->
Using a separate filesystem for the container store.
There is a very clear explanation.

Resources