Skip to content

feat: support connecting to a pocket-ic server running inside a Docker container. #4271

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

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

vincent-dfinity
Copy link
Contributor

@vincent-dfinity vincent-dfinity commented Jun 12, 2025

Description

The pr supports connecting to a pocket-ic server running inside a Docker container.

  1. This is the docker image which simply runs pocket-ic server on port 8081.
  2. Run dfx start --docker <IMAGE_NAME> to tell dfx to run a container.
  3. dfx will initialize the pocket-ic instance and gateway on the running server.

Fixes # (issue)

How Has This Been Tested?

Manually tested so far by starting, deploying, and stopping.

Checklist:

  • The title of this PR complies with Conventional Commits.
  • I have edited the CHANGELOG accordingly.
  • I have made corresponding changes to the documentation.

@vincent-dfinity vincent-dfinity changed the title feat: support running pocket-ic inside a docker container. feat: support connecting to a pocket-ic server running inside a Docker container. Jun 17, 2025
Comment on lines +540 to +541
if std::process::Command::new("docker")
.args(["--version"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if the command is available, docker might still fail if the daemon is not running.

@@ -286,6 +342,8 @@ fn pocketic_start_thread(
}
}
};
println!("port: {}", port);
Copy link
Contributor

Choose a reason for hiding this comment

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

Left-over debug output?

"-p",
format!("{}:{}", bind_address.port(), bind_address.port()).as_str(),
"-p",
"8081:8081",
Copy link
Contributor

Choose a reason for hiding this comment

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

This assumes a fixed port on the host without an option to override.

bind_address = convert_to_docker_bind_address(bind_address);
cmd.args([
"-p",
format!("{}:{}", bind_address.port(), bind_address.port()).as_str(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Inside the container a fixed port could be used for simplicity.

Comment on lines +124 to +125
let output = std::process::Command::new("docker")
.args(["exec", container_id.as_str(), "cat", "pocket-ic-port"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the (host) port retrieved from the docker container? I'd expect the host port to be stored on the host and mapped to a (fixed) port used in the docker container.

"8081:8081",
]);
cmd.args(["-d", docker_image.as_str()]);
cmd.stdout(std::process::Stdio::piped());
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd also expect the -v option to be used in order to mount the state to be persisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants