su
apt-get install podman golang-github-containernetworking-plugin-dnsname
cd /usr/lib/podman
wget https://github.com/containers/gvisor-tap-vsock/releases/download/v0.7.1/gvproxy-linux-amd64
mv gvproxy-linux-amd64 gvproxy
chmod +x gvproxy
exit
- create folder and edit config:
mkdir -p /home/projects/pdm-nginx
cd /home/projects/pdm-nginx
nano nginx.conf
nginx.conf
events {}
http {
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://pdm-node-instance:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
}
- create Dockerfile file
nano Dockerfile
# nginx-config/Dockerfile
FROM nginx:latest
COPY nginx.conf /etc/nginx/nginx.conf
- build image
podman build -t pdm-nginx .
- create folder and edit config
mkdir -p /home/projects/pdm-node
cd /home/projects/pdm-node
nano index.js
- create index.js file
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('Hello, podman');
});
const port = 8080;
server.listen(port, () => {
console.log(`Server running at http://localhost:${port}/`);
});
- create Dockerfile file
nano Dockerfile
# node-app/Dockerfile
FROM node:18
WORKDIR /app
#COPY package*.json ./
#RUN npm install
COPY index.js .
EXPOSE 8080
CMD ["node", "index.js"]
- build image
podman build -t pdm-node .
- create pod
podman pod create --name pdm-n -p 8080:80
- create node instance and insert into the pod
podman run -d --pod pdm-n --name pdm-node-instance pdm-node
- create nginx instance and insert into the pod
podman run -d --pod pdm-n --name pdm-nginx-instance pdm-nginx
- restart pod
podman pod stop pdm-n
podman pod start pdm-n
check the url
curl http://localhost:8080
Result:
curl: (56) Recv failure: Connection reset by peer
- Show container list
podman ps --pod
- if some containers are missing:
podman ps --pod -a
- We can see
878f7bb9e056 localhost/pdm-nginx:latest nginx -g daemon o... About a minute ago Exited (1) 43 seconds ago 0.0.0.0:8080->80/tcp pdm-nginx-instance f4d6d3870d55 pdm-n
- check logs
podman logs 878f7bb9e056
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: IPv6 listen already enabled
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2024/01/12 10:56:00 [emerg] 1#1: host not found in upstream "pdm-node-instance" in /etc/nginx/nginx.conf:9
nginx: [emerg] host not found in upstream "pdm-node-instance" in /etc/nginx/nginx.conf:9
-
for some reason can't reach the node instance
-
remove the container from the pod
podman rm pdm-nginx-instance
- list all containers and pods
podman ps --pod -a
- try to add the nginx instance to pod
podman run -d --pod pdm-n --name pdm-nginx-instance pdm-nginx
- restart pod
podman pod stop pdm-n
podman pod start pdm-n
-
I think it was better to create the node image first, because the nginx calls to node instance, but it had not been created yet
-
check the url
curl http://localhost:8080
Result:
Hello, podman