Here is the article:
I can’t install Solana CLI from Docker on Mac
As a developer on Anchor, one of the most popular blockchain projects in the space, you are probably no stranger to working with Docker. In fact, your development environment probably includes a containerized setup for your applications and testing environments.
However, when it comes to 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 get an error saying that Solana CLI cannot be installed due to a conflicting environment variable or permission issue.
The Problem
To fix this issue, we need to modify the Anchor development Dockerfile
to install Solana CLI in a way that resolves these conflicts and allows it to install successfully. Here’s what needs to change:
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 made two key changes:
- We download and install the Solana CLI from the CDN instead of using a local copy in the
FROM
statement.
- We use the
RUN
statement to install the Solana CLI by downloading it, making it executable withchmod +x /tmp/solana-cli
, and adding it to the system PATH.
Why this works
By installing the Solana CLI from the CDN and then moving it to the system PATH, we avoid any conflicts with the Docker image that comes pre-installed with your container. The /tmp
directory is also used as a temporary place to store the installation process, ensuring that the executable file is not left behind after the installation.
Back on track
With these modifications, you should now be able to install Solana CLI from Docker without any issues. Don’t forget to update your Dockerfile
accordingly and run it again to make sure everything works as expected.
Full Code Example
For reference, here is the full modified code:
Use an official Solana image for the pinned application containerFROM solana-cli: latest
Download Solana CLI from CDNRUN sh -c "curl -sfL > /tmp/solana-cli && \
chmod +x /tmp/solana-cli && \
export PATH=$PATH:/tmp/solana-cli"
Make Solana CLI executable and add it to the system PATHRUN 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!