{"id":23407706,"url":"https://github.com/bestia-dev/docker_rust_minimal","last_synced_at":"2026-01-21T12:35:27.861Z","repository":{"id":46214621,"uuid":"290457757","full_name":"bestia-dev/docker_rust_minimal","owner":"bestia-dev","description":"Docker is cool. Lets do Rust with Docker","archived":false,"fork":false,"pushed_at":"2025-09-21T11:43:37.000Z","size":210,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-21T13:23:33.968Z","etag":null,"topics":["maintained","ready-for-use","tutorial"],"latest_commit_sha":null,"homepage":"","language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bestia-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-08-26T09:48:11.000Z","updated_at":"2025-09-21T11:43:40.000Z","dependencies_parsed_at":"2024-03-02T23:20:25.672Z","dependency_job_id":"257deb51-2823-44e2-9231-338d72c71da1","html_url":"https://github.com/bestia-dev/docker_rust_minimal","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bestia-dev/docker_rust_minimal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestia-dev%2Fdocker_rust_minimal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestia-dev%2Fdocker_rust_minimal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestia-dev%2Fdocker_rust_minimal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestia-dev%2Fdocker_rust_minimal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bestia-dev","download_url":"https://codeload.github.com/bestia-dev/docker_rust_minimal/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestia-dev%2Fdocker_rust_minimal/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28632847,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T04:47:28.174Z","status":"ssl_error","status_checked_at":"2026-01-21T04:47:22.943Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["maintained","ready-for-use","tutorial"],"created_at":"2024-12-22T14:29:38.855Z","updated_at":"2026-01-21T12:35:27.845Z","avatar_url":"https://github.com/bestia-dev.png","language":"Dockerfile","readme":"\u003c!-- markdownlint-disable MD041 --\u003e\n[//]: # (auto_md_to_doc_comments segment start A)\n\n# docker_rust_minimal\n\n**Docker is cool. Lets do Rust with Docker**  \n***version: 1.0  date: 2020-08-26 author: [bestia.dev](https://bestia.dev) repository: [GitHub](https://github.com/bestia-dev/docker_rust_minimal)***  \n\n ![maintained](https://img.shields.io/badge/maintained-green)\n ![ready_for_use](https://img.shields.io/badge/ready_for_use-green)\n ![tutorial](https://img.shields.io/badge/tutorial-yellow)\n ![License](https://img.shields.io/badge/license-MIT-blue.svg)\n ![docker_rust_minimal](https://bestia.dev/webpage_hit_counter/get_svg_image/517782432.svg)\n\nHashtags: #rustlang #tutorial #docker  \nMy projects on Github are more like a tutorial than a finished product: [bestia-dev tutorials](https://github.com/bestia-dev/tutorials_rust_wasm).\n\n## WSL2\n\nOn my Win10 I have WSL2 - Windows subsystem for Linux.  \nI had WSL 1 for a while, but it was not a true Linux kernel and Docker did not work with WSL 1.  \nWSL2 is a revolution. With it I have a lightweight virtual machine with a true Linux kernel. Great !  \nWin10 must be version 1903 or higher. My machine did not automatically update to that yet, so I needed the workaround.\nI needed to register in the Microsoft Insiders program.  \n\u003chttps://insider.windows.com/en-us/getting-started\u003e  \nIt uses the same account you use for other Microsoft service.  \nNow in `Check for updates` I can see the update to version 19041. Just do it!  \n\n### Installing WSL2\n\n\u003chttps://docs.microsoft.com/en-us/windows/wsl/install-win10#update-to-wsl-2\u003e\n\n```powershell\n# Open PowerShell as Administrator\ndism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart\n# restart and update to WSL2\ndism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart\n# restart your machine. Set WSL2 as default\nwsl --set-default-version 2\n# I get the error: WSL 2 requires an update to its kernel component. \n# visit https://aka.ms/wsl2kernel and do the update\n# I choose to install the Debian distro:\nhttps://www.microsoft.com/sl-si/p/debian/9msvkqc78pk6?rtc=1\n# give it a password you will remember\n# then in linux bash\n$ sudo apt update\n$ sudo apt dist-upgrade\n```\n\n## Rust\n\nI will try to compile all my Rust code to Linux or Wasm.  \nThe Windows OS is less and less interesting to me. It is really good for GUI applications. But I am not interested in those, because it limits the use of the program to only that OS. This kind of platform vendor-lock-in because of the GUI is stupid.  \nI will try to make applications that are separated into server/backend and client/frontend. The server will work on Linux. It means everywhere. The server can be on the same machine, in a virtual machine, in the WSL2, on another machine in the local network or anywhere on the internet. So everywhere.  \nThe client/frontend will work inside the browser with Wasm. It means everywhere.  \nAll will be written in Rust. Full stack Rust.  \nIt sounds like a good cross-platform solution.  To me.\n\n## Docker\n\nInstall Docker in windows with WSL2 support  \n\u003chttps://docs.docker.com/docker-for-windows/wsl/\u003e  \nDownload and install the stable version from  \n\u003chttps://hub.docker.com/editions/community/docker-ce-desktop-windows/\u003e  \nUse the whale icon in the notification area to see the Docker containers.\n\n```powershel\n# run in powershell to check the installation\ndocker version\ndocker run hello-world\n```\n\nDocker engine is inside WSL2. Great!  \nWindows is only a GUI. Everything really is running in Linux.  \nThis is the future.\n\n## Container for Rust building\n\nFor now we don't need to install Rust on our Debian.  \nJust pull the image for Rust building standalone 100% statically linked app with musl.  \nIt already has installed everything we need for Rust. Easy.  \n\u003chttps://blog.sedrik.se/posts/my-docker-setup-for-rust/\u003e\n\n```bash\n# bash commands\n$ docker pull ekidd/rust-musl-builder\n# create an alias to be used easily to run the container\n$ alias rust-musl-builder='docker run --rm -it -v \"$(pwd)\":/home/rust/src ekidd/rust-musl-builder'\n# docker container can be run for only one execution and then removed\n# --rm means the container is removed after execution\n# -it means interactive + pseudo-tty (not in background)\n# -v Volume links a read/write host directory to the container file system\n# $(pwd) means \"Present Working Directory\" and has nothing to do with passwords\n# docker commands finish with the image name\n```\n\n## Git\n\nWe will need git in Debian for our example program.\n\n```bash\nsudo apt install git\ngit --version\ngit config --global user.name \"Your Name\"\ngit config --global user.email \"youremail@yourdomain.com\"\n```  \n\nClone this repo:  \n\n```bash\ncd ~\nmkdir rustprojects\ncd rustprojects\ngit clone git@github.com:bestia-dev/docker_rust_minimal.git\n\n```  \n\n## Building a CLI program\n\nOur pwd Present Working Directory is the cloned project.\n\n```bash\ncd ~/rustprojects/docker_rust_minimal\n```\n\nWe will use the alias to run a docker container. And after that we will give the command to execute in the container. We want to build the Rust project.\n\n```bash\nrust-musl-builder cargo build --release\n```\n\nThat's it. The docker container was spinned, the volume was linked, the project was built. We can find the result in `target/x86_64-unknown-linux-musl/release/hello` on the host OS Debian.  \n\n## Make it small\n\nNow we have a binary (executable) and we want to deploy it somewhere.\nWe will try to make it as small as possible. Maybe that is not smart for every scenario out there, but let's have a look.  \n\n```bash\n# let \"strip\" the binary for minimal size\n$ strip target/x86_64-unknown-linux-musl/release/hello\n# from 3MB to 300kB ?!\n```\n\n## Build the Docker image\n\nWe want to use docker to encapsulate all the needed files and configuration so the person on the other side does not need to worry about it.\nWe need to have a Dockerfile in our Working Directory. It is already in this git repo. It looks simple like this:\n\n```bash\nFROM scratch\nCOPY target/x86_64-unknown-linux-musl/release/hello /\nCMD [\"/hello\"]\n```\n\n`scratch` is the smallest possible docker image base. We can use it because our binary is statically linked to everything including `musl`. The next smallest image base is Alpine Linux. Only 5 MB. The next can be Debian Slim 88 MB. You see the difference in size.  \nWe need to copy only our binary file to the image.  \nWhen the container is run, it will execute our binary.  \nNow build this image:\n\n```bash\nalias utc='date -u +\"%Y-%m-%dT%H-%M-%S\"'\ndocker build --no-cache -t scratch_hello -t scratch_hello:$(utc) .\n```\n\nFor deployment reasons we want to give a version to the image. It is difficult to make this smart. I will just use the UTC date and time.  \n`--no-cache` for this example we avoid caching  \n`-t` means tag or name. There can be more than one tag curiously.  \n`.` means the Dockerfile is here in the Working Directory  \nWe can see it now in our list of local docker images:\n\n```bash\ndocker images\n```\n\nIt is only 305kB. Woohoo!\n\n## Run the containerized CLI\n\nWe can now run the docker container with our CLI just as we would run the app itself:  \n\n```bash\ndocker run --rm scratch_hello\n```\n\n`--rm` means remove the container after execution  \nWe can run it also from the `Windows Command Prompt` and `PowerShell terminal`.\nIncredible !\n\n## Deploy\n\nDocker Hub is a website to share docker images easily.  Alternatively it can be saved to a tar file and then transfered, copied and finally loaded.\n\n```bash\ndocker save --output scratch_hello-2020-08-26T11-45-51.tar scratch_hello:2020-08-26T11-45-51\n```\n\nOn the other side:  \n\n```bash\ndocker load --input scratch_hello-2020-08-26T11-45-51.tar\ndocker tag scratch_hello:2020-08-26T11-45-51 scratch_hello:latest\ndocker run scratch_hello\n```\n\nAdding the tag `latest` makes it easier to call that image later.  \n\n## Open-source and free as a beer\n\nMy open-source projects are free as a beer (MIT license).  \nI just love programming.  \nBut I need also to drink. If you find my projects and tutorials helpful, please buy me a beer by donating to my [PayPal](https://paypal.me/LucianoBestia).  \nYou know the price of a beer in your local bar ;-)  \nSo I can drink a free beer for your health :-)  \n[Na zdravje!](https://translate.google.com/?hl=en\u0026sl=sl\u0026tl=en\u0026text=Na%20zdravje\u0026op=translate) [Alla salute!](https://dictionary.cambridge.org/dictionary/italian-english/alla-salute) [Prost!](https://dictionary.cambridge.org/dictionary/german-english/prost) [Nazdravlje!](https://matadornetwork.com/nights/how-to-say-cheers-in-50-languages/) 🍻\n\n[//bestia.dev](https://bestia.dev)  \n[//github.com/bestia-dev](https://github.com/bestia-dev)  \n[//bestiadev.substack.com](https://bestiadev.substack.com)  \n[//youtube.com/@bestia-dev-tutorials](https://youtube.com/@bestia-dev-tutorials)  \n\n[//]: # (auto_md_to_doc_comments segment end A)\n","funding_links":["https://paypal.me/LucianoBestia"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbestia-dev%2Fdocker_rust_minimal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbestia-dev%2Fdocker_rust_minimal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbestia-dev%2Fdocker_rust_minimal/lists"}