Skip to content

Instantly share code, notes, and snippets.

@luizanao
Forked from kaaquist/podman_macos.md
Last active January 26, 2022 13:43
Show Gist options
  • Save luizanao/1540093c9b5981d10fa1738c3182dedd to your computer and use it in GitHub Desktop.
Save luizanao/1540093c9b5981d10fa1738c3182dedd to your computer and use it in GitHub Desktop.

Revisions

  1. luizanao revised this gist Jan 21, 2022. 1 changed file with 56 additions and 8 deletions.
    64 changes: 56 additions & 8 deletions podman_macos.md
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,28 @@
    # Podman with docker-compose on MacOS.
    > Podman an alternative to Docker Desktop on MacOS
    This is a fork of @kaaquist [original gist](https://gist.github.com/kaaquist/dab64aeb52a815b935b11c86202761a3). Thanks for sharing!

    Getting podman installed and started is super easy.
    Just use `brew` to install it.
    ```
    > brew install podman
    ```
    Now since podman uses a VM just like the Docker Client on MacOS we need to initialize that and start it.

    I'd recommend creating the VM with arealistic set of resources, for me it was:
    ```
    > podman machine init
    > podman machine init --cpus 4 --disk-size 50 --memory 4096
    > podman machine start
    ```

    Now we are set to go.

    If you want you can create a symlink so podman can be executed with "docker" command.
    ```
    > ln -s /usr/local/bin/podman /usr/local/bin/docker
    ```

    Now most of the commands in podman are the same so try `podman images` and you will get a list of images.
    Else the `podman --help` command list all the help you need.

    @@ -34,17 +40,59 @@ First we need to find the port it is exposed on in the VM.
    ```
    > podman system connection ls
    ```
    This command will show all the users/connections you have available - defaults: core or user.

    You can switch between them by:
    ```
    > podman system connection default podman-machine-default-root
    # or podman-machine-default if you feel like
    ```
    I choose root connection since core user has some limitations that bother me, such don't allow me to expose lower ports (80, 443, etc)

    Then we need to take that port and create a forward ssh connection to that.

    Then we need to take that port and create a forward ssh connection to that.
    ```
    > ssh -fnNT -L/tmp/podman.sock:/run/user/1000/podman/podman.sock -i ~/.ssh/podman-machine-default ssh://core@localhost:<port to socket> -o StreamLocalBindUnlink=yes
    > ssh -fnNT -L/tmp/podman.sock:/run/user/1000/podman/podman.sock -i ~/.ssh/podman-machine-default ssh://root@localhost:<port to socket> -o StreamLocalBindUnlink=yes
    > export DOCKER_HOST='unix:///tmp/podman.sock'
    ```
    Second, we expose the `DOCKER_HOST` env variable that is used by `docker-compose`.
    Be aware that if the connection is disconnected one needs to delete/overwrite the `/tmp/podman.socket` to run the forward command got o Pro-tip:


    **Pro-tip**: Instead of keep repeating this process every time you close your terminal session / restart computer, you can let `~/.bashrc` do that for you.

    Be aware that if the connection is disconnected one needs to delete/overwrite the `/tmp/podman.socket` to run the forward command.
    Copy this to `~/.bashrc` to auto-load podman ssh forwarding and env var everytime you open a new terminal session.
    ```
    # Podman containers
    export DOCKER_HOST='unix:///tmp/podman.sock'
    warmup_podman(){
    is_ssh_tunel_setup=$(ps aux | grep -i "ssh -fnNT -L/tmp/podman.sock:/run/podman/podman.sock" | grep -v grep | wc -l)
    if [[ $is_ssh_tunel_setup -eq 0 ]]; then
    port=$(podman system connection ls | grep -i root | awk '{print $3}' | sed -n 's/^.*localhost:\([^/]*\).*/\1/p')
    ssh -fnNT -L/tmp/podman.sock:/run/podman/podman.sock -i ~/.ssh/podman-machine-default ssh://root@localhost:${port} -o StreamLocalBindUnlink=yes
    fi
    }
    warmup_podman
    ```

    ### Test it

    To make sure podman is runnning fine:
    ```
    podman run -it ubuntu:latest
    ```
    in a new terminal session:
    ```
    podman ps
    docker ps
    ```
    You should see similar outputs since docker binary is using podman banckend.
    docker-compose should also work as normal, using podman backend.

    Overall findings is that if one only runs single images then it is fairly easy to get going using podman. But if you rely on the `compose` part to orchestrate the containers in a bigger setup of different images with networking etc. then `podman` is a lot less easy to get working "out of the box". There is a lot of googling involved and then it still seems that there are a lot of the features that are not too easy to get working. I did have a lot of issues getting the right permissions to mount drives into the images. One of the main features with podman is that it is rootless. Which is great but it means that you need to understand what permissions a container needs before it fully works.
    I have tried to use the `podman-compose` as the goto instead of `docker-compose`, but I had a hard time even getting it installed, and there were alot of issues where it could not load images from the local repository, so in the end that is why I decided to use `docker-compose` and not `podman-compose`. Another thing is that `podman-compose` is also developed by people not really part of the `podman` community it seems, or it is not set to be the frist choice by the `podman` community. So it seems that it is a project that has its own agenda, and is run by a few people and not as many as the `podman` community.
    For now I got it working but I will say that there are many wheels that need tuning and kept updated to have the setup running in a daily development environment.
    So if you, like me, just want to use the tools and not need to finetune all the time, it seems a little like there is a way to go before `podman` takes over the MacOS setup. Next for me is to try to setup everything on my linux laptop and see if this works easier out of the box.
    ### Knowing issue:

    For my particular docker-compose version (`docker-compose version 1.29.2, build 5becea4c`) I had issues building containers that we solved by:
    ```
    # docker-compose issue https://github.com/containers/podman/issues/11326
    export COMPOSE_DOCKER_CLI_BUILD=0
    ```
  2. @kaaquist kaaquist revised this gist Oct 15, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion podman_macos.md
    Original file line number Diff line number Diff line change
    @@ -37,7 +37,7 @@ First we need to find the port it is exposed on in the VM.

    Then we need to take that port and create a forward ssh connection to that.
    ```
    > ssh -fnNT -L/tmp/podman.sock:/run/user/1000/podman/podman.sock -i ~/.ssh/podman-machine-default ssh://core@localhost:<port to socket>
    > ssh -fnNT -L/tmp/podman.sock:/run/user/1000/podman/podman.sock -i ~/.ssh/podman-machine-default ssh://core@localhost:<port to socket> -o StreamLocalBindUnlink=yes
    > export DOCKER_HOST='unix:///tmp/podman.sock'
    ```
    Second, we expose the `DOCKER_HOST` env variable that is used by `docker-compose`.
  3. @kaaquist kaaquist revised this gist Oct 8, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion podman_macos.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # Podman with docker-compose on MacOS.
    > Podman an alternative to Docker Client on MacOS
    > Podman an alternative to Docker Desktop on MacOS
    Getting podman installed and started is super easy.
    Just use `brew` to install it.
  4. @kaaquist kaaquist revised this gist Oct 8, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion podman_macos.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # Podman with docker-compose on MacOS.
    > Podman and alternative to Docker Client on MacOS
    > Podman an alternative to Docker Client on MacOS
    Getting podman installed and started is super easy.
    Just use `brew` to install it.
  5. @kaaquist kaaquist revised this gist Sep 19, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion podman_macos.md
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ If you want you can create a symlink so podman can be executed with "docker" com
    > ln -s /usr/local/bin/podman /usr/local/bin/docker
    ```
    Now most of the commands in podman are the same so try `podman images` and you will get a list of images.
    Else the `podman --help` command on its own list all the help you need.
    Else the `podman --help` command list all the help you need.


    To get `docker-compose` without the docker client for mac. You can install it using the `brew` command.
  6. @kaaquist kaaquist revised this gist Sep 19, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions podman_macos.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    # Podman with docker-compose on MacOS.
    > Podman and alternative to Docker Client on MacOS
    Getting podman installed and started is super easy.
    Just use `brew` to install it.
    ```
  7. @kaaquist kaaquist revised this gist Sep 19, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion podman_macos.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # Podman with docker-compose on MacOS.
    > Podman and alternative to Docker Client on MacOS
    > Podman and alternative to Docker Client on MacOS
    Getting podman installed and started is super easy.
    Just use `brew` to install it.
    ```
  8. @kaaquist kaaquist revised this gist Sep 19, 2021. 1 changed file with 9 additions and 8 deletions.
    17 changes: 9 additions & 8 deletions podman_macos.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ Just use `brew` to install it.
    ```
    > brew install podman
    ```
    Now since podman uses a VM just like the Docker Client on MacOS we need til initialize that and start it.
    Now since podman uses a VM just like the Docker Client on MacOS we need to initialize that and start it.
    ```
    > podman machine init
    > podman machine start
    @@ -20,7 +20,7 @@ Now most of the commands in podman are the same so try `podman images` and you w
    Else the `podman --help` command on its own list all the help you need.


    To get `docker-compose` without the docker client for mac. You can install the using `brew` command.
    To get `docker-compose` without the docker client for mac. You can install it using the `brew` command.
    ```
    > brew install docker-compose
    ```
    @@ -34,15 +34,16 @@ First we need to find the port it is exposed on in the VM.
    > podman system connection ls
    ```

    Then we need to take that port and create a forwawrd ssh connection to that.
    Then we need to take that port and create a forward ssh connection to that.
    ```
    > ssh -fnNT -L/tmp/podman.sock:/run/user/1000/podman/podman.sock -i ~/.ssh/podman-machine-default ssh://core@localhost:<port to socket>
    > export DOCKER_HOST='unix:///tmp/podman.sock'
    ```
    Secound command we expose the `DOCKER_HOST` env variable that is used by `docker-compose`.
    Second, we expose the `DOCKER_HOST` env variable that is used by `docker-compose`.

    Be aware, that is the connection is disconnected one need to delete/overwrite the `/tmp/podman.socket` to run the forward command.
    Be aware that if the connection is disconnected one needs to delete/overwrite the `/tmp/podman.socket` to run the forward command.

    Overall findings is that if one only use single images run then it is fairly easy to get going using podman. But if you relay on the `compose` part to orchestrate the containers in a bigger setup of different images and networking etc. then `podman` is a lot less easy to get working "out of the box". There is a lot of googling involved and then still it seems that there is still a lot of the features that is not to easy to get working. I did have a lot of issues getting the right permissions to mount drives into the images. One of the main features with podman is that it is rootless. Which is great but it makes you need to understand what permissins a container need before it fully works.
    I have tried to use the `podman-compose` as the goto instead of `docker-compose`, but I had a hard time even getting it installed, and there were alot of issues where it could not load images from the local repository, so that is why in the end I decided to use `docker-compose` and not `podman-compose`. Another thing is that `podman-compose` is also developed by people not really part of the `podman` community, or it is not set to be the frist choice by the `podman` community. So it seems that it is a project that has its own agenda, and is run by a few people and not as many as the `podman` community.

    Overall findings is that if one only runs single images then it is fairly easy to get going using podman. But if you rely on the `compose` part to orchestrate the containers in a bigger setup of different images with networking etc. then `podman` is a lot less easy to get working "out of the box". There is a lot of googling involved and then it still seems that there are a lot of the features that are not too easy to get working. I did have a lot of issues getting the right permissions to mount drives into the images. One of the main features with podman is that it is rootless. Which is great but it means that you need to understand what permissions a container needs before it fully works.
    I have tried to use the `podman-compose` as the goto instead of `docker-compose`, but I had a hard time even getting it installed, and there were alot of issues where it could not load images from the local repository, so in the end that is why I decided to use `docker-compose` and not `podman-compose`. Another thing is that `podman-compose` is also developed by people not really part of the `podman` community it seems, or it is not set to be the frist choice by the `podman` community. So it seems that it is a project that has its own agenda, and is run by a few people and not as many as the `podman` community.
    For now I got it working but I will say that there are many wheels that need tuning and kept updated to have the setup running in a daily development environment.
    So if you, like me, just want to use the tools and not need to finetune all the time, it seems a little like there is a way to go before `podman` takes over the MacOS setup. Next for me is to try to setup everything on my linux laptop and see if this works easier out of the box.
  9. @kaaquist kaaquist created this gist Sep 19, 2021.
    48 changes: 48 additions & 0 deletions podman_macos.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    # Podman with docker-compose on MacOS.
    > Podman and alternative to Docker Client on MacOS
    Getting podman installed and started is super easy.
    Just use `brew` to install it.
    ```
    > brew install podman
    ```
    Now since podman uses a VM just like the Docker Client on MacOS we need til initialize that and start it.
    ```
    > podman machine init
    > podman machine start
    ```
    Now we are set to go.

    If you want you can create a symlink so podman can be executed with "docker" command.
    ```
    > ln -s /usr/local/bin/podman /usr/local/bin/docker
    ```
    Now most of the commands in podman are the same so try `podman images` and you will get a list of images.
    Else the `podman --help` command on its own list all the help you need.


    To get `docker-compose` without the docker client for mac. You can install the using `brew` command.
    ```
    > brew install docker-compose
    ```
    When that is done you now should have the ability to use `docker-compose` with `podman`.

    On MacOS the podman project does not expose the `podman.socket` which is similar to `docker.socket`, by default. So to get `docker-compose` working one needs to expose the socket.

    To get the socket running run the following commands.
    First we need to find the port it is exposed on in the VM.
    ```
    > podman system connection ls
    ```

    Then we need to take that port and create a forwawrd ssh connection to that.
    ```
    > ssh -fnNT -L/tmp/podman.sock:/run/user/1000/podman/podman.sock -i ~/.ssh/podman-machine-default ssh://core@localhost:<port to socket>
    > export DOCKER_HOST='unix:///tmp/podman.sock'
    ```
    Secound command we expose the `DOCKER_HOST` env variable that is used by `docker-compose`.

    Be aware, that is the connection is disconnected one need to delete/overwrite the `/tmp/podman.socket` to run the forward command.

    Overall findings is that if one only use single images run then it is fairly easy to get going using podman. But if you relay on the `compose` part to orchestrate the containers in a bigger setup of different images and networking etc. then `podman` is a lot less easy to get working "out of the box". There is a lot of googling involved and then still it seems that there is still a lot of the features that is not to easy to get working. I did have a lot of issues getting the right permissions to mount drives into the images. One of the main features with podman is that it is rootless. Which is great but it makes you need to understand what permissins a container need before it fully works.
    I have tried to use the `podman-compose` as the goto instead of `docker-compose`, but I had a hard time even getting it installed, and there were alot of issues where it could not load images from the local repository, so that is why in the end I decided to use `docker-compose` and not `podman-compose`. Another thing is that `podman-compose` is also developed by people not really part of the `podman` community, or it is not set to be the frist choice by the `podman` community. So it seems that it is a project that has its own agenda, and is run by a few people and not as many as the `podman` community.