Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 530: Fix container engine detection when podman-docker installed #538

Closed
wants to merge 4 commits into from

Conversation

alexhunt7
Copy link

@alexhunt7 alexhunt7 commented Mar 20, 2021

When using podman with podman-docker installed, cross will fail to build with a permission error.

cross build --release --target=aarch64-unknown-linux-gnu

Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
error: failed to open: /target/release/.cargo-lock

Caused by:
  Permission denied (os error 13)

If using cross from master, this can be worked around by specifying CROSS_CONTAINER_ENGINE=podman, but this does not work for the latest released version (v0.2.1).

Even though this has a workaround, this should be fixed such that we do not need to specify CROSS_CONTAINER_ENGINE. Simply defaulting to podman first fixes it.

Resolves #530

@reitermarkus
Copy link
Member

If both podman and docker are installed, docker should be the default. Is there a way to detect if docker is podman-docker?

@alexhunt7
Copy link
Author

alexhunt7 commented Mar 31, 2021

If both podman and docker are installed, docker should be the default.

Why? If anything, I'd assume the opposite, since docker requires a daemon and root privileges to run, while podman can be run by normal users. Most distributions ship with podman in their default repositories, but not docker. Many of these users will have podman-docker installed, which causes cross to hit the permissions error if cross treats it like docker.

I assume there are very few users who would have both docker and podman installed. Even if we do hit one, defaulting to using podman causes no harm, while defaulting to docker breaks things.

Is there a way to detect if docker is podman-docker?

If podman-docker is installed, /usr/bin/docker will be a script that simply passes all the arguments to podman. There is also a symlink from /run/docker.sock to /run/podman/podman.sock . Searching for the word podman in /usr/bin/docker is probably the simplest way. That, or calling docker --version, which will say it is podman.

[alex:~] $ docker --version
podman version 3.0.1
[alex:~] 17s $ dnf repoquery -l podman-docker | grep -v /usr/share/man
Last metadata expiration check: 0:00:43 ago on Tue 30 Mar 2021 10:33:43 PM PDT.
/usr/bin/docker
/usr/lib/tmpfiles.d/podman-docker.conf
/usr/bin/docker
/usr/lib/tmpfiles.d/podman-docker.conf
[alex:~] $ cat /usr/bin/docker
#!/usr/bin/sh
[ -f /etc/containers/nodocker ] || \
echo "Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg." >&2
exec /usr/bin/podman "$@"
[alex:~] $ cat /usr/lib/tmpfiles.d/podman-docker.conf
L+  /run/docker.sock   -    -    -     -   /run/podman/podman.sock
[alex:~] $ ll /run/docker.sock
lrwxrwxrwx. 1 root root 23 Mar 30 22:29 /run/docker.sock -> /run/podman/podman.sock

From within a container, there are several (potentially unreliable) ways containers/podman#3586 .

@Elinvynia
Copy link

What is needed to get this merged?

Currently this issue is preventing me from using cross at all and I would like to help.

@Emilgardis
Copy link
Member

I think this change make sense, I don't use podman but the reasoning to use it when both docker and podman is installed makes sense to me.

Right now we're locked by CI (#609), and we're in the process of a migration, see rust-embedded/wg#590

@Alexhuszagh
Copy link
Contributor

The CI issues have been fixed so this could be rebased and if it makes sense to the other maintainers, merged. I'm personally of the opinion defaulting to podman over docker would be a good idea as well.

@Alexhuszagh Alexhuszagh added the A-container-engine Area: container engines label May 28, 2022
@Alexhuszagh Alexhuszagh requested a review from a team as a code owner May 29, 2022 11:34
Copy link
Contributor

@Alexhuszagh Alexhuszagh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed the merge issues, and I'd personally approve of these changes since podman defaults to less permissions and doesn't require a daemon. I'll let another maintainer be the final judge, however, since although podman aims to be entirely compatible with docker, this is a change in the default cross behavior.

@Emilgardis
Copy link
Member

@reitermarkus you previosuly mentioned this shouldn't be done. has your position changed?

@reitermarkus
Copy link
Member

I think it makes sense to be the default on Linux. I think on macOS and Windows podman is only usable as a remote client so it should not be the default for that reason.

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented May 31, 2022

I think it makes sense to be the default on Linux. I think on macOS and Windows podman is only usable as a remote client so it should not be the default for that reason.

I've updated it to do this by default. I've used the check to default to podman first if the OS is Linux, rather than use podman on anything other than Windows or macOS, since podman can't run natively on anything other than Linux anyway I believe (FreeBSD jails or Dragonfly zones aren't identical) even if it gets support on the BSDs or similar (also, I doubt Docker will ever support FreeBSD).

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented Jun 4, 2022

Uh I tried quashing multiple commits into one, but I think I failed spectacularly, which was not what I intended based on the documentation. Also, I've confirmed this works on docker for Windows, podman for Windows, podman-docker on WSL, podman on WSL, and docker & podman on Linux.
@cross/issue-530

Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jun 4, 2022
Currently, docker detection fails under a few cases:
1. If `podman_docker` is installed, so the filename is docker but the actual executable is podman.
2. If the executable has a suffix, such as `.exe` on Windows, because we check if the executable `ends_with(DOCKER)`.

The only reliable way to fix both these issues, IE, if the actual engine is docker and not an alias, and if the executable does not contain a suffix, is to query the container engine. This might not be ideal for performance reasons, but is the only reliable way to fix these issues.

Closes cross-rs#530.
Closes cross-rs#538.
@Alexhuszagh Alexhuszagh mentioned this pull request Jun 4, 2022
bors bot added a commit that referenced this pull request Jun 5, 2022
755: Fix docker detection. r=Emilgardis a=Alexhuszagh

Currently, docker detection fails under a few cases:
1. If `podman_docker` is installed, so the filename is docker but the actual executable is podman.
2. If the executable has a suffix, such as `.exe` on Windows, because we check if the executable `ends_with(DOCKER)`.

The only reliable way to fix both these issues, IE, if the actual engine is docker and not an alias, and if the executable does not contain a suffix, is to query the container engine. This might not be ideal for performance reasons, but is the only reliable way to fix these issues.

Closes #530.
Closes #538.

Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
@bors bors bot closed this in 6baac54 Jun 5, 2022
@bors bors bot closed this in #755 Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-container-engine Area: container engines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failure when podman-docker is installed
5 participants