3

I found some library that can replace docker-compose in podman but it is still under development, so my question is how can I run multiple container together, currently I am using my bash script to run all but it is good just for the first time not updating the container.

I'd prefer at first if there is any way in podman rather than using some other tool.

library (under development) --> https://github.com/muayyad-alsadi/podman-compose

GeoCom
  • 1,290
  • 2
  • 12
  • 33
  • 2
    Possible duplicate of [There is any "Podman Compose"?](https://stackoverflow.com/questions/55154393/there-is-any-podman-compose) – tgogos Jul 05 '19 at 07:13
  • actually it is not, as i mentioned that library is under development. either I need replacement or official way to do it. – GeoCom Jul 05 '19 at 08:31

1 Answers1

2

I think the Kubernetes Pod concept is what you're looking for, or at least it allows you to run multiple containers together by following a well-established standard.

My first approach was like you, to do everything as a command to see it working, something like:

# Create a pod, publishing port 8080/TCP from internal 80/TCP
$ podman pod create \
  --name my-pod \
  --publish 8080:80/TCP \
  --publish 8113:113/TCP

# Create a first container inside the pod
$ podman run --detach \
  --pod my-pod \
  --name cont1-name \
  --env MY_VAR="my val" \
  nginxdemos/hello

# Create a second container inside the pod
$ podman run --detach \
  --pod my-pod \
  --name cont2-name \
  --env MY_VAR="my val" \
  greboid/nullidentd

# Check by
$ podman container ls; podman pod ls

Now that you have a pod, you can export it as a Pod manifest by using podman generate kube my-pod > my-pod.yaml.

As soon as you try your own examples, you will see how not everything is exported as you would expect (like networks or volumes), but at least it serves you as a base where you can continue to work.

Assuming the same example, in a YAML Pod manifest, it looks like this my-pod.yaml:

# Created with podman-2.2.1
apiVersion: v1
kind: Pod
metadata:
  labels:
    app: my-pod
  name: my-pod
spec:
  containers:
  # Create the first container: Dummy identd server on 113/TCP
  - name: cont2-name
    image: docker.io/greboid/nullidentd:latest
    command: [ "/usr/sbin/inetd", "-i" ]
    env:
    - name: MY_VAR
      value: my val
    # Ensure not to overlap other 'containerPort' values within this pod
    ports:
    - containerPort: 113
      hostPort: 8113
      protocol: TCP
    workingDir: /
  # Create a second container.
  - name: cont1-name
    image: docker.io/nginxdemos/hello:latest
    command: [ "nginx", "-g", "daemon off;" ]
    env:
    - name: MY_VAR
      value: my val
    # Ensure not to overlap other 'containerPort' values within this pod
    ports:
    - containerPort: 80
      hostPort: 8080
      protocol: TCP
    workingDir: /
  restartPolicy: Never
status: {}

When this file is used like this:

# Use a Kubernetes-compatible Pod manifest to create and run a pod
$ podman play kube my-pod.yaml

# Check
$ podman container ls; podman pod ls

# Output
CONTAINER ID  IMAGE                                COMMAND               CREATED         STATUS            PORTS                                        NAMES
1a53a5c0f076  docker.io/nginxdemos/hello:latest    nginx -g daemon o...  8 seconds ago   Up 6 seconds ago  0.0.0.0:8080->80/tcp, 0.0.0.0:8113->113/tcp  my-pod-cont1-name
351065b66b55  docker.io/greboid/nullidentd:latest  /usr/sbin/inetd -...  10 seconds ago  Up 6 seconds ago  0.0.0.0:8080->80/tcp, 0.0.0.0:8113->113/tcp  my-pod-cont2-name
e61c68752e35  k8s.gcr.io/pause:3.2                                       14 seconds ago  Up 7 seconds ago  0.0.0.0:8080->80/tcp, 0.0.0.0:8113->113/tcp  b586ca581129-infra
POD ID        NAME    STATUS   CREATED         INFRA ID      # OF CONTAINERS
b586ca581129  my-pod  Running  14 seconds ago  e61c68752e35  3

You will be able to access the 'Hello World' served by nginx at 8080, and the dummy identd server at 8113.

CieNTi
  • 41
  • 1
  • 8