Error: invalid config provided: published or exposed ports must be defined when the pod is created:

118 views Asked by At

Create the Pod with Port Mappings:

podman pod create --name $PODNAME

Build PostgreSQL Container Image:

podman build -t $FILM_CONTAINER_NAME_POSTGRES --build-arg SQL_FILE=$FILM_DB_SQL ./docker/db

Run PostgreSQL Container in the Pod with Port Mapping:

podman run -d --pod $PODNAME --name $FILM_CONTAINER_NAME_POSTGRES -p 54321:5432 $FILM_CONTAINER_NAME_POSTGRES

Why can't I create a container inside a pod, where each container should run on a specific port?

Suppose creating the ports when creating the pod, but then how should each container know on which port it should run?

There is a way to solve it with adding --share cgroup, but then if I try to connect from a container to another, the connection would be refused.

Build Film App Container Image:

podman build -t $FILM_CONTAINER_NAME .

Run Film App Container in the Pod with Port Mapping:

podman run -t --name $FILM_CONTAINER_NAME --pod $PODNAME \
  -e POSTGRESQL_DATABASE="$FILM_DB_NAME" \
  -e POSTGRESQL_USER=postgres \
  -e POSTGRESQL_PASSWORD=postgres \
  -e POSTGRESQL_DATASOURCE="$FILM_DATASOURCE" \
  -e POSTGRESQL_SERVICE_PORT="$FILM_DB_PORT" \
  -p 8081:8080 \
  $FILM_CONTAINER_NAME

However, this is solved with --net=host, but then I must remove port of the container (second container).

Any suggestions without using YAML or Kubernetes?

Expecting to run each container on a specific port.

0

There are 0 answers