Solana: Can’t install Solana CLI from Docker on Mac

Here is the article:

Can’t install Solana CLI from Docker on a Mac

As a developer at Anchor, one of the most popular blockchain projects in the space, you are no stranger to working with Docker. In fact, your development environment probably includes a containerized setup for your applications and testing environments.

However, when installing the latest version of Solana CLI (also known as solana-cli), you may encounter an unexpected error while trying to install it from Docker. Specifically, you receive an error saying that Solana CLI cannot be installed due to a conflicting environment variable or permission issue.

Problem

To fix this issue, we need to modify the Dockerfile for Anchor development to install Solana CLI in a way that resolves these conflicts and allows it to install successfully. Here’s what needs to be changed:

From solana-cli: Latest

RUN sh -c "curl -sfL > /tmp/solana-cli && \

chmod +x /tmp/solana-cli && \

export PATH=$PATH:/tmp/solana-cli"

What’s changed

In the modified Dockerfile, we’ve made two major changes:

  • We’re downloading and installing the Solana CLI from a CDN instead of using a local copy of the FROM directive.
  • We use the RUN command to install the Solana CLI by downloading it, making it executable with chmod +x /tmp/solana-cli, and adding it to the system PATH.

Why this works

By installing the Solana CLI from a CDN and moving it to the system PATH, we avoid conflicts with the pre-installed Docker image with your container. The /tmp directory is also used as a temporary place to store the installation process, ensuring that the executable is not left behind after the installation.

Getting back on track

With these changes in place, you should now be able to install the Solana CLI from Docker without any issues. Be sure to update your Dockerfile accordingly and run it again to make sure everything is working as expected.

Full Code Example

For reference, here is the full modified code:


Use an official Solana image for the anchor application container

From solana-cli:latest


Download the Solana CLI from a CDN

RUN sh -c "curl -sfL > /tmp/solana-cli && \

chmod +x /tmp/solana-cli && \

export PATH=$PATH:/tmp/solana-cli


Make the Solana CLI executable and add it to the system PATH

RUN sh -c "curl -sfL > /tmp/solana-cli && \

chmod +x /tmp/solana-cli && \

export PATH=$PATH:/tmp/solana-cli"

With these changes, you should be able to successfully install Solana CLI from Docker on your Mac. Happy development!

Commentaires

0 Commentaire Écrire un commentaire

Laisser un commentaire