This container provides a Solana development environment, pre-installed with the Solana CLI, Anchor framework, Rust, Node.js, and other essential tools. It eliminates the need for local configuration, allowing you to focus on learning Anchor basics.
When starting off with anchor, the first hurdle is getting your contract to compile/ anchor to work. This container does this for you building the example contract and having it ready for you to deploy. When learning you mainly deal with two files: Anchor.toml lib.rs
you can edit lib.rs using emacs inside the container and then build your updated code. The container is ready for your contract to be deployed, and at this point you will have to configure Anchor.toml
# Pull the latest image
docker pull hogyzen12/anchor-docker:latest
# Run with a new Solana keypair (recommended for testing)
docker run -it hogyzen12/anchor-docker:latest
Your shell will now be in the testbuild directory.
This is the simple Hello example built and ready to deploy.
You will have to set up the Anchor.toml file with the network you want to deploy on - devnet is reccomended
- Ubuntu 22.04: Lightweight and reliable base image
- Emacs: Preinstalled text editor for further development
- Rust Toolchain: Pre-installed using
rustup
- Solana CLI: Built from source
- Anchor CLI: Installed for simplified Solana program development
- Node.js 20.x: Included for managing JavaScript-based dependencies and tools
- Automated Key Management: Support for both existing and new Solana keypairs
- Fully configured with essential libraries and dependencies for Solana development
This is the fastest way to get started:
-
Pull the container:
docker pull hogyzen12/anchor-docker:latest
-
Run the container:
- With a new keypair:
docker run -it hogyzen12/anchor-docker:latest
- With your existing keypair:
docker run -v /path/to/your/id.json:/tmp/id.json -it hogyzen12/anchor-docker:latest /tmp/id.json
- With a new keypair:
This option takes longer but allows for customization:
-
Clone the repository:
git clone https://github.com/hogyzen12/anchor-docker.git cd anchor-docker
-
Build the Docker image - This is not quick:
docker build -t anchor-docker:latest .
-
Run the container:
- With a new keypair:
docker run -it anchor-docker:latest
- With your existing keypair:
docker run -v /path/to/your/id.json:/tmp/id.json -it anchor-docker:latest /tmp/id.json
- With a new keypair:
If you have an existing Solana keypair:
- Locate your
id.json
file (usually in~/.config/solana/id.json
) - Mount it when running the container as shown above
- The container will automatically configure Solana and anchor to use this keypair
If you don't provide a keypair:
- The container automatically generates a new keypair
- The keypair is stored at
/usr/src/app/testbuild/id.json
- Solana CLI is automatically configured to use this keypair
Verify your setup inside the container:
-
Check Rust Installation
rustc --version cargo --version
Expected output:
rustc 1.75.0 (xx-xx-xxxx) cargo 1.xx.x (xx-xx-xxxx)
-
Check Solana Installation
solana --version solana address # Should show your keypair's address
Expected output:
solana-cli 1.18.26 (source) <your-solana-address>
-
Check Anchor Installation
anchor --version
Expected output:
anchor-cli 0.30.1
-
Check Node.js Installation
node -v npm -v
Expected output:
v20.x.x 9.x.x
# List running containers
docker ps
# Enter an existing container
docker exec -it <container_id_or_name> /bin/bash
# Stop the container
docker stop <container_id_or_name>
# Remove the container
docker rm <container_id_or_name>
# Create a new Anchor project
anchor init my_project
# Build your project
anchor build
# Run tests
anchor test
# Deploy your program
anchor deploy
docker pull hogyzen12/anchor-docker:latest
git pull # Update your local repository
docker build -t anchor-docker:latest .
- The container comes with a pre-initialized Anchor project at
/usr/src/app/testbuild
- All necessary tools and dependencies are pre-installed and configured
- The container uses Rust 1.75.0 by default
- Your Solana keypair location will be automatically configured in the Solana CLI
- The container includes
emacs
for in-container development