08-28-2022, 12:15 AM
How to Install the Solidity Compiler via Docker on Ubuntu?
<div>
<div class="kk-star-ratings kksr-auto kksr-align-left kksr-valign-top" data-payload="{"align":"left","id":"611841","slug":"default","valign":"top","ignore":"","reference":"auto","class":"","count":"1","readonly":"","score":"5","best":"5","gap":"5","greet":"Rate this post","legend":"5\/5 - (1 vote)","size":"24","width":"142.5","_legend":"{score}\/{best} - ({count} {votes})","font_factor":"1.25"}">
<div class="kksr-stars">
<div class="kksr-stars-inactive">
<div class="kksr-star" data-star="1" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="2" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="3" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="4" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="5" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
</p></div>
<div class="kksr-stars-active" style="width: 142.5px;">
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
</p></div>
</div>
<div class="kksr-legend" style="font-size: 19.2px;"> 5/5 – (1 vote) </div>
</div>
<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube"><a href="https://blog.finxter.com/how-to-install-the-solidity-compiler-via-docker-on-ubuntu/"><img src="https://blog.finxter.com/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=https%3A%2F%2Fi.ytimg.com%2Fvi%2FjT9DK2kmoEQ%2Fhqdefault.jpg" alt="YouTube Video"></a><figcaption></figcaption></figure>
<div class="wp-block-file"><object class="wp-block-file__embed" data="https://blog.finxter.com/wp-content/uploads/2022/08/Solidity-Blog-Finxter-Compiler-Docker.pdf" type="application/pdf" style="width:100%;height:600px" aria-label="Embed of Solidity-Blog-Finxter-Compiler-Docker."></object><a id="wp-block-file--media-fbab0f45-d7f4-459d-b8f2-41c3b8a2109b" href="https://blog.finxter.com/wp-content/uploads/2022/08/Solidity-Blog-Finxter-Compiler-Docker.pdf">Solidity-Blog-Finxter-Compiler-Docker</a><a href="https://blog.finxter.com/wp-content/uploads/2022/08/Solidity-Blog-Finxter-Compiler-Docker.pdf" class="wp-block-file__button" download aria-describedby="wp-block-file--media-fbab0f45-d7f4-459d-b8f2-41c3b8a2109b">Download</a></div>
<p>In this article, we continue building on our previous topic, the Solidity compiler installation:</p>
<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f30d.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Previous Topic</strong>: <a href="https://blog.finxter.com/how-to-install-the-solidity-compiler-with-npm/" data-type="post" data-id="606118">Solidity Compiler Installation (NPM)</a></p>
<p>The previous article was focused on an installation via <em>npm</em>, and in this article, we’ll go through the installation and use of the Solidity compiler via <em>Docker</em>. </p>
<p>Our goal is to get more familiar with the possibilities of this approach, as well as to get introduced to the technology that “runs the show”. This knowledge and experience will enable us to recognize the reasons behind choosing any of the approaches in the future, depending on the real-world needs of our projects.</p>
<h2>What is Docker?</h2>
<p>Before we go into details about the Docker installation of <code>solc</code>, let’s first get introduced to what Docker is. </p>
<p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f4a1.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <em><strong>Docker</strong> is an open platform for developing, shipping, and running applications… Docker provides the ability to package and run an application in a loosely isolated environment called a container… Containers are lightweight and contain everything needed to run the application, so you do not need to rely on what is currently installed on the host.</em></p>
<p><strong>Source</strong>: <a rel="noreferrer noopener" href="https://docs.docker.com/get-started/overview/" target="_blank"><em>https://docs.docker.com/get-started/overview/</em></a></p>
<p>There are some parts of the description I’ve deliberately left out (separated by the symbol …) because they’re not essential to our understanding of the technology. </p>
<p>Now, let’s dissect the Docker description: the keywords of our interest are <em><strong>platform</strong></em>,<em> <strong>isolated environment</strong></em>, and <em><strong>container</strong></em>. Let’s quickly dive into each of those next</p>
<h3>Platform</h3>
<p>A <strong>platform</strong> is a software framework that supports a specific function or a goal. </p>
<p>The goal Docker supports is enabling a piece of software (application, service, etc.) to correctly run, regardless of the target environment. </p>
<p>For us, this means running the Solidity compiler, i.e. feeding it with the input source code and producing the output bytecode in the form of <code>.abi</code> and <code>.bin</code> files.</p>
<h3>Isolated Environment</h3>
<p>By mentioning an <strong>isolated environment</strong>, we remember the concept of virtualization learned about earlier, meaning that Docker enables our software to run as intended by providing it with the resources in form of software libraries, network access, remote services, and other dependencies.</p>
<h3>Container</h3>
<p>Docker ensures the resources are provided without additional intervention by arranging them in a package called a <strong>container</strong>. Containers begin their lifecycle as images that we most commonly download and run. </p>
<p>We can also create a Docker image, but that’s another story. </p>
<p>Running an image creates a live instance of it, a container. Before it can be used, a Docker image has to be prepared, meaning that someone should install and configure all the required resources needed for the software to run. </p>
<p>Preparation of a Docker image falls in the domain of <em><a rel="noreferrer noopener" href="https://blog.finxter.com/devops-specialist-income-and-opportunity/" data-type="post" data-id="310928" target="_blank">DevOps</a></em>, i.e. Development and Operations: </p>
<p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f4a1.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <em>“DevOps engineers manage the operations of software development, implementing engineering tools and knowledge of the software development process to streamline software updates and creation.” </em></p>
<p><strong>Source</strong>: <a href="https://www.indeed.com/hire/c/info/devops-engineer"><em>https://www.indeed.com/hire/c/info/devops-engineer</em></a></p>
<p>Also, read our article:</p>
<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f30d.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Recommended Article</strong>: <a href="https://blog.finxter.com/top-20-skills-of-a-devops-engineer/" data-type="URL" data-id="https://blog.finxter.com/top-20-skills-of-a-devops-engineer/" target="_blank" rel="noreferrer noopener">Top 20 Skills Every DevOps Engineer Ought to Have</a></p>
<h2>Using Solidity Compiler via Docker</h2>
<p>Now that we have introduced Docker in general, we are continuing with the installation of the Solidity compiler via Docker.</p>
<p>First, we have to check if Docker is present on our system by simultaneously checking the Docker version:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ docker version
bash: /usr/bin/docker: No such file or directory</pre>
<p>As our check shows, we have to install Docker on our system before we can use it. The installation process via the Ubuntu repository is made of several steps (<a href="https://docs.docker.com/engine/install/ubuntu/" target="_blank" rel="noreferrer noopener"><em>https://docs.docker.com/engine/install/ubuntu/</em></a>):</p>
<h3>Step 1: Update the apt package index</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ sudo apt update
…
Reading package lists... Done
Building dependency tree Reading state information... Done
All packages are up to date.</pre>
<h3>Step 2: Install packages</h3>
<p>Installation of additional packages; we need these packages to enable the installation process accessing the repository over the secure HTTPS connection (note the backslash symbol <code>\</code> for the multiline command):</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ sudo apt install \
ca-certificates \
curl gnupg lsb-release
...
The following additional packages will be installed: gnupg-l10n gnupg-utils gpg-wks-server
Suggested packages: parcimonie xloadimage
The following NEW packages will be installed: ca-certificates curl gnupg gnupg-l10n gnupg-utils gpg-wks-server lsb-release
...
Do you want to continue? [Y/n] y
...
</pre>
<h3>Step 3: Add Docker GPG key</h3>
<p>Adding the Docker’s official GPG key:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ sudo mkdir \
-p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| sudo gpg – dearmor -o /etc/apt/keyrings/docker.gpg
</pre>
<p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/2139.png" alt="ℹ" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Info</strong>:<em> “GPG, or GNU Privacy Guard, is a public key cryptography implementation. This allows for the secure transmission of information between parties and can be used to verify that the origin of a message is genuine.” </em></p>
<p><strong>Source</strong>: <a href="https://www.digitalocean.com/community/tutorials/how-to-use-gpg-to-encrypt-and-sign-messages"><em>https://www.digitalocean.com/community/tutorials/how-to-use-gpg-to-encrypt-and-sign-messages</em></a></p>
<h3>Step 4: Set up repository</h3>
<p>Setting up the repository by writing to <code>docker.list</code> file.</p>
<p>The <code>echo</code> command evaluates the text inside the <code>$( )</code>, populates it with the command outputs (in parentheses), and sends it via stdin to system utility <code>sudo tee</code> with root privileges, which in turn overwrites the <code>docker.list</code> file and omits the output by redirecting it to <code>/dev/null</code>:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ echo \ "deb [arch=$(dpkg – print-architecture) \
signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee \
/etc/apt/sources.list.d/docker.list > /dev/null
</pre>
<p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/2139.png" alt="ℹ" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Info</strong>: Repositories added by mistake can be removed from Ubuntu 20.04 by selectively deleting them in <code>/etc/apt/sources.list.d/</code> directory.</p>
<h3>Step 5: Update apt package index</h3>
<p>Updating the apt package index (once again):</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ sudo apt update
...
Reading package lists... Done
Building dependency tree Reading state information... Done
All packages are up to date.
</pre>
<h3>Step 6: Install Docker</h3>
<p>Installing Docker (the latest stable version) and its components:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Reading package lists... Done
Building dependency tree Reading state information... Done
The following additional packages will be installed: docker-ce-rootless-extras docker-scan-plugin pigz slirp4netns
Suggested packages: aufs-tools cgroupfs-mount | cgroup-lite
The following NEW packages will be installed: containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras docker-compose-plugin docker-scan-plugin pigz slirp4netns
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 108 MB of archives.
After this operation, 449 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
...
</pre>
<p>Let’s check the Docker version once again:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ docker version
Client: Docker Engine - Community Version: 20.10.17 API version: 1.41 Go version: go1.17.11 Git commit: 100c701 Built: Mon Jun 6 23:02:57 2022 OS/Arch: linux/amd64 Context: default Experimental: true Server: Docker Engine - Community Engine: Version: 20.10.17 API version: 1.41 (minimum version 1.12) Go version: go1.17.11 Git commit: a89b842 Built: Mon Jun 6 23:01:03 2022 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.7 GitCommit: 0197261a30bf81f1ee8e6a4dd2dea0ef95d67ccb runc: Version: 1.1.3 GitCommit: v1.1.3-0-g6724737 docker-init: Version: 0.19.0 GitCommit: de40ad0
</pre>
<p>Now that we’re sure that our Docker installation went through and the Docker Engine version we have is <code>20.20.17</code> (at the time of writing this article). The next step is getting the Docker image with the Solidity compiler.</p>
<p>Docker images are identified by their <em>release organization</em>, <em>image name</em> (shorter, images), and <em>tag</em>, i.e. label that makes them unique. In general, we can download a Docker image by referencing it with its <code>organization/image:tag</code> marker. </p>
<p>We will download a Docker image of the Solidity compiler by specifying its marker as <code>ethereum/solc:stable</code> for a stable version, and <code>ethereum/solc:nightly</code> for the bleeding edge, potentially unstable version. </p>
<p>We can also specify a distinct version of the Solidity compiler by setting a tag to a specific version, e.g. <code>ethereum/solc:0.5.4</code>.</p>
<p>We will do three things with one Docker command: we’ll download the image, instantiate (run) a container from the image and print the container usage (flag – help):</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">docker run ethereum/solc:stable – help</pre>
<p>Sure enough, we’d like to compile our Solidity files, so we’ll make three preparations (<strong>First</strong>, <strong>Second</strong>, <strong>Third</strong>):</p>
<p><strong>First</strong>: Create a local directory containing our <a href="https://blog.finxter.com/solidity/" data-type="URL" data-id="https://blog.finxter.com/solidity/" target="_blank" rel="noreferrer noopener">Solidity</a> source code (I’ll use <code>1_Storage.sol</code> from the <a href="https://blog.finxter.com/smart-contracts-and-evm/" data-type="post" data-id="92507" target="_blank" rel="noreferrer noopener">Remix contracts</a> folder by creating an empty <a href="https://blog.finxter.com/layout-of-a-solidity-source-file/" data-type="post" data-id="455693">f</a><a href="https://blog.finxter.com/layout-of-a-solidity-source-file/" data-type="post" data-id="455693" target="_blank" rel="noreferrer noopener">i</a><a href="https://blog.finxter.com/layout-of-a-solidity-source-file/" data-type="post" data-id="455693">le</a> and pasting the content into it):</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ mkdir ~/solidity_src/ && cd ~/solidity_src/
$ touch 1_Storage.sol
</pre>
<p><strong>Second</strong>: You can write your own contract for testing purposes or just open the <code>1_Storage.sol</code> with your favorite <a href="https://blog.finxter.com/how-to-edit-a-text-file-in-windows-powershell/" data-type="post" data-id="236823" target="_blank" rel="noreferrer noopener">text editor</a> and paste the contents from <code>1_Storage.sol</code> example in Remix.</p>
<p><strong>Third</strong>: Run a Docker container (we already have the image so the download procedure will be skipped); command flag <code>-v</code> mounts our local <code>~/solidity_src</code> directory to the container’s path <code>/sources</code>, path <code>ethereum/solc:stable</code> selects the Docker image to run a container, command flag <code>-o</code> sets the output location for the compiled files, <code>--abi</code> and <code>--bin</code> activate the generation of both <code>.abi</code> and <code>.bin</code> files, and the path <code>/sources/1_Storage.sol</code> selects the source file for compilation:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ docker run -v ~/solidity_src:/sources ethereum/solc:stable -o /sources/output – abi – bin /sources/1_Storage.sol
Compiler run successful. Artifact(s) can be found in directory "/sources/output".
</pre>
<p>When checking our <code>solidity_src</code> directory, we’ll discover a new directory output, created by the Solidity compiler, containing both <code>.abi</code> and <code>.bin</code> files.</p>
<p>Docker also enables us to use the standard JSON interface, and it is a recommended approach when using the compiler with a toolchain. This interface doesn’t require mounted directories if the JSON input is self-contained, in other words, all the code is already contained in the source files and there are no references to external, imported files:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">docker run ethereum/solc:stable – standard-json < input.json > output.json</pre>
<p>Since we haven’t done any examples using the JSON interface, we’ll suspend this approach until a later time.</p>
<h2><a></a>Conclusion</h2>
<p>This article introduced us to a Solidity-supporting technology called Docker. </p>
<p>Of course, our main focus is on an ecosystem consisting of <a href="https://blog.finxter.com/introduction-to-smart-contracts-and-solidity/" data-type="post" data-id="445145" target="_blank" rel="noreferrer noopener">Solidity</a>, <a href="https://blog.finxter.com/smart-contracts-and-evm/" data-type="post" data-id="92507" target="_blank" rel="noreferrer noopener">Ethereum</a>, <a href="https://blog.finxter.com/how-much-does-a-blockchain-engineer-make/" data-type="post" data-id="161686" target="_blank" rel="noreferrer noopener">blockchain technology</a>, etc., but I recognized an opportunity of making a detour and walking us through the process of setting up and using the Solidity compiler via the Docker platform. Therefore, although initially unplanned, we’re also gaining some <a href="https://blog.finxter.com/top-20-skills-of-a-devops-engineer/" data-type="post" data-id="332626" target="_blank" rel="noreferrer noopener">DevOps skills</a>.</p>
<p>In the first and only chapter (yeah, I’m a bit surprised as well) we’ve set the mining charges by getting to know what Docker is. Then we blew a big piece of rock away by discovering how to install Docker on Ubuntu Linux (and by extension, some other operating systems). I believe this article will prove useful and provide multiple tips and tricks in terms of setting your development environment for Solidity on Ubuntu Linux. Besides that and personally speaking, it was always useful to gain secondary knowledge whenever I learned a specific topic, and I’m sure you’ll have the same experience.</p>
<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f30d.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Recommended Tutorial</strong>: <a href="https://blog.finxter.com/solidity-crash-course/" data-type="post" data-id="445146" target="_blank" rel="noreferrer noopener">Solidity Crash Course</a> (by Matija)</p>
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<h2><a href="https://academy.finxter.com/university/solidity-basics/" target="_blank" rel="noreferrer noopener" title="https://academy.finxter.com/university/solidity-basics/">Learn Solidity Course</a></h2>
<p>Solidity is the programming language of the future.</p>
<p>It gives you the rare and sought-after superpower to program against the “Internet Computer”, i.e., against decentralized Blockchains such as <em>Ethereum</em>, <em>Binance Smart Chain</em>, <em>Ethereum Classic</em>, <em>Tron</em>, and <em>Avalanche </em> – to mention just a few Blockchain infrastructures that support Solidity.</p>
<p>In particular, Solidity allows you to<em> create smart contracts</em>, i.e., pieces of code that automatically execute on specific conditions in a completely decentralized environment. For example, smart contracts empower you to create your own <em>decentralized autonomous organizations</em> (DAOs) that run on Blockchains without being subject to centralized control.</p>
<p>NFTs, DeFi, DAOs, and Blockchain-based games are all based on smart contracts.</p>
<p><a href="https://academy.finxter.com/university/solidity-basics/" target="_blank" rel="noreferrer noopener" title="https://academy.finxter.com/university/solidity-basics/">This course</a> is a simple, low-friction introduction to creating your first smart contract using the Remix IDE on the Ethereum testnet – without fluff, significant upfront costs to purchase ETH, or unnecessary complexity.</p>
<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><a href="https://academy.finxter.com/university/solidity-basics/" target="_blank" rel="noopener"><img loading="lazy" src="https://blog.finxter.com/wp-content/uploads/2021/10/image-121.png" alt="" class="wp-image-37299" width="491" height="287" srcset="https://blog.finxter.com/wp-content/uploads/2021/10/image-121.png 982w, https://blog.finxter.com/wp-content/uplo...00x175.png 300w, https://blog.finxter.com/wp-content/uplo...68x448.png 768w" sizes="(max-width: 491px) 100vw, 491px" /></a></figure>
</div>
</div>
https://www.sickgaming.net/blog/2022/08/...on-ubuntu/
<div>
<div class="kk-star-ratings kksr-auto kksr-align-left kksr-valign-top" data-payload="{"align":"left","id":"611841","slug":"default","valign":"top","ignore":"","reference":"auto","class":"","count":"1","readonly":"","score":"5","best":"5","gap":"5","greet":"Rate this post","legend":"5\/5 - (1 vote)","size":"24","width":"142.5","_legend":"{score}\/{best} - ({count} {votes})","font_factor":"1.25"}">
<div class="kksr-stars">
<div class="kksr-stars-inactive">
<div class="kksr-star" data-star="1" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="2" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="3" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="4" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="5" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
</p></div>
<div class="kksr-stars-active" style="width: 142.5px;">
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
</p></div>
</div>
<div class="kksr-legend" style="font-size: 19.2px;"> 5/5 – (1 vote) </div>
</div>
<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube"><a href="https://blog.finxter.com/how-to-install-the-solidity-compiler-via-docker-on-ubuntu/"><img src="https://blog.finxter.com/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=https%3A%2F%2Fi.ytimg.com%2Fvi%2FjT9DK2kmoEQ%2Fhqdefault.jpg" alt="YouTube Video"></a><figcaption></figcaption></figure>
<div class="wp-block-file"><object class="wp-block-file__embed" data="https://blog.finxter.com/wp-content/uploads/2022/08/Solidity-Blog-Finxter-Compiler-Docker.pdf" type="application/pdf" style="width:100%;height:600px" aria-label="Embed of Solidity-Blog-Finxter-Compiler-Docker."></object><a id="wp-block-file--media-fbab0f45-d7f4-459d-b8f2-41c3b8a2109b" href="https://blog.finxter.com/wp-content/uploads/2022/08/Solidity-Blog-Finxter-Compiler-Docker.pdf">Solidity-Blog-Finxter-Compiler-Docker</a><a href="https://blog.finxter.com/wp-content/uploads/2022/08/Solidity-Blog-Finxter-Compiler-Docker.pdf" class="wp-block-file__button" download aria-describedby="wp-block-file--media-fbab0f45-d7f4-459d-b8f2-41c3b8a2109b">Download</a></div>
<p>In this article, we continue building on our previous topic, the Solidity compiler installation:</p>
<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f30d.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Previous Topic</strong>: <a href="https://blog.finxter.com/how-to-install-the-solidity-compiler-with-npm/" data-type="post" data-id="606118">Solidity Compiler Installation (NPM)</a></p>
<p>The previous article was focused on an installation via <em>npm</em>, and in this article, we’ll go through the installation and use of the Solidity compiler via <em>Docker</em>. </p>
<p>Our goal is to get more familiar with the possibilities of this approach, as well as to get introduced to the technology that “runs the show”. This knowledge and experience will enable us to recognize the reasons behind choosing any of the approaches in the future, depending on the real-world needs of our projects.</p>
<h2>What is Docker?</h2>
<p>Before we go into details about the Docker installation of <code>solc</code>, let’s first get introduced to what Docker is. </p>
<p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f4a1.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <em><strong>Docker</strong> is an open platform for developing, shipping, and running applications… Docker provides the ability to package and run an application in a loosely isolated environment called a container… Containers are lightweight and contain everything needed to run the application, so you do not need to rely on what is currently installed on the host.</em></p>
<p><strong>Source</strong>: <a rel="noreferrer noopener" href="https://docs.docker.com/get-started/overview/" target="_blank"><em>https://docs.docker.com/get-started/overview/</em></a></p>
<p>There are some parts of the description I’ve deliberately left out (separated by the symbol …) because they’re not essential to our understanding of the technology. </p>
<p>Now, let’s dissect the Docker description: the keywords of our interest are <em><strong>platform</strong></em>,<em> <strong>isolated environment</strong></em>, and <em><strong>container</strong></em>. Let’s quickly dive into each of those next</p>
<h3>Platform</h3>
<p>A <strong>platform</strong> is a software framework that supports a specific function or a goal. </p>
<p>The goal Docker supports is enabling a piece of software (application, service, etc.) to correctly run, regardless of the target environment. </p>
<p>For us, this means running the Solidity compiler, i.e. feeding it with the input source code and producing the output bytecode in the form of <code>.abi</code> and <code>.bin</code> files.</p>
<h3>Isolated Environment</h3>
<p>By mentioning an <strong>isolated environment</strong>, we remember the concept of virtualization learned about earlier, meaning that Docker enables our software to run as intended by providing it with the resources in form of software libraries, network access, remote services, and other dependencies.</p>
<h3>Container</h3>
<p>Docker ensures the resources are provided without additional intervention by arranging them in a package called a <strong>container</strong>. Containers begin their lifecycle as images that we most commonly download and run. </p>
<p>We can also create a Docker image, but that’s another story. </p>
<p>Running an image creates a live instance of it, a container. Before it can be used, a Docker image has to be prepared, meaning that someone should install and configure all the required resources needed for the software to run. </p>
<p>Preparation of a Docker image falls in the domain of <em><a rel="noreferrer noopener" href="https://blog.finxter.com/devops-specialist-income-and-opportunity/" data-type="post" data-id="310928" target="_blank">DevOps</a></em>, i.e. Development and Operations: </p>
<p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f4a1.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <em>“DevOps engineers manage the operations of software development, implementing engineering tools and knowledge of the software development process to streamline software updates and creation.” </em></p>
<p><strong>Source</strong>: <a href="https://www.indeed.com/hire/c/info/devops-engineer"><em>https://www.indeed.com/hire/c/info/devops-engineer</em></a></p>
<p>Also, read our article:</p>
<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f30d.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Recommended Article</strong>: <a href="https://blog.finxter.com/top-20-skills-of-a-devops-engineer/" data-type="URL" data-id="https://blog.finxter.com/top-20-skills-of-a-devops-engineer/" target="_blank" rel="noreferrer noopener">Top 20 Skills Every DevOps Engineer Ought to Have</a></p>
<h2>Using Solidity Compiler via Docker</h2>
<p>Now that we have introduced Docker in general, we are continuing with the installation of the Solidity compiler via Docker.</p>
<p>First, we have to check if Docker is present on our system by simultaneously checking the Docker version:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ docker version
bash: /usr/bin/docker: No such file or directory</pre>
<p>As our check shows, we have to install Docker on our system before we can use it. The installation process via the Ubuntu repository is made of several steps (<a href="https://docs.docker.com/engine/install/ubuntu/" target="_blank" rel="noreferrer noopener"><em>https://docs.docker.com/engine/install/ubuntu/</em></a>):</p>
<h3>Step 1: Update the apt package index</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ sudo apt update
…
Reading package lists... Done
Building dependency tree Reading state information... Done
All packages are up to date.</pre>
<h3>Step 2: Install packages</h3>
<p>Installation of additional packages; we need these packages to enable the installation process accessing the repository over the secure HTTPS connection (note the backslash symbol <code>\</code> for the multiline command):</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ sudo apt install \
ca-certificates \
curl gnupg lsb-release
...
The following additional packages will be installed: gnupg-l10n gnupg-utils gpg-wks-server
Suggested packages: parcimonie xloadimage
The following NEW packages will be installed: ca-certificates curl gnupg gnupg-l10n gnupg-utils gpg-wks-server lsb-release
...
Do you want to continue? [Y/n] y
...
</pre>
<h3>Step 3: Add Docker GPG key</h3>
<p>Adding the Docker’s official GPG key:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ sudo mkdir \
-p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| sudo gpg – dearmor -o /etc/apt/keyrings/docker.gpg
</pre>
<p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/2139.png" alt="ℹ" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Info</strong>:<em> “GPG, or GNU Privacy Guard, is a public key cryptography implementation. This allows for the secure transmission of information between parties and can be used to verify that the origin of a message is genuine.” </em></p>
<p><strong>Source</strong>: <a href="https://www.digitalocean.com/community/tutorials/how-to-use-gpg-to-encrypt-and-sign-messages"><em>https://www.digitalocean.com/community/tutorials/how-to-use-gpg-to-encrypt-and-sign-messages</em></a></p>
<h3>Step 4: Set up repository</h3>
<p>Setting up the repository by writing to <code>docker.list</code> file.</p>
<p>The <code>echo</code> command evaluates the text inside the <code>$( )</code>, populates it with the command outputs (in parentheses), and sends it via stdin to system utility <code>sudo tee</code> with root privileges, which in turn overwrites the <code>docker.list</code> file and omits the output by redirecting it to <code>/dev/null</code>:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ echo \ "deb [arch=$(dpkg – print-architecture) \
signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee \
/etc/apt/sources.list.d/docker.list > /dev/null
</pre>
<p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/2139.png" alt="ℹ" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Info</strong>: Repositories added by mistake can be removed from Ubuntu 20.04 by selectively deleting them in <code>/etc/apt/sources.list.d/</code> directory.</p>
<h3>Step 5: Update apt package index</h3>
<p>Updating the apt package index (once again):</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ sudo apt update
...
Reading package lists... Done
Building dependency tree Reading state information... Done
All packages are up to date.
</pre>
<h3>Step 6: Install Docker</h3>
<p>Installing Docker (the latest stable version) and its components:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Reading package lists... Done
Building dependency tree Reading state information... Done
The following additional packages will be installed: docker-ce-rootless-extras docker-scan-plugin pigz slirp4netns
Suggested packages: aufs-tools cgroupfs-mount | cgroup-lite
The following NEW packages will be installed: containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras docker-compose-plugin docker-scan-plugin pigz slirp4netns
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 108 MB of archives.
After this operation, 449 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
...
</pre>
<p>Let’s check the Docker version once again:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ docker version
Client: Docker Engine - Community Version: 20.10.17 API version: 1.41 Go version: go1.17.11 Git commit: 100c701 Built: Mon Jun 6 23:02:57 2022 OS/Arch: linux/amd64 Context: default Experimental: true Server: Docker Engine - Community Engine: Version: 20.10.17 API version: 1.41 (minimum version 1.12) Go version: go1.17.11 Git commit: a89b842 Built: Mon Jun 6 23:01:03 2022 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.7 GitCommit: 0197261a30bf81f1ee8e6a4dd2dea0ef95d67ccb runc: Version: 1.1.3 GitCommit: v1.1.3-0-g6724737 docker-init: Version: 0.19.0 GitCommit: de40ad0
</pre>
<p>Now that we’re sure that our Docker installation went through and the Docker Engine version we have is <code>20.20.17</code> (at the time of writing this article). The next step is getting the Docker image with the Solidity compiler.</p>
<p>Docker images are identified by their <em>release organization</em>, <em>image name</em> (shorter, images), and <em>tag</em>, i.e. label that makes them unique. In general, we can download a Docker image by referencing it with its <code>organization/image:tag</code> marker. </p>
<p>We will download a Docker image of the Solidity compiler by specifying its marker as <code>ethereum/solc:stable</code> for a stable version, and <code>ethereum/solc:nightly</code> for the bleeding edge, potentially unstable version. </p>
<p>We can also specify a distinct version of the Solidity compiler by setting a tag to a specific version, e.g. <code>ethereum/solc:0.5.4</code>.</p>
<p>We will do three things with one Docker command: we’ll download the image, instantiate (run) a container from the image and print the container usage (flag – help):</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">docker run ethereum/solc:stable – help</pre>
<p>Sure enough, we’d like to compile our Solidity files, so we’ll make three preparations (<strong>First</strong>, <strong>Second</strong>, <strong>Third</strong>):</p>
<p><strong>First</strong>: Create a local directory containing our <a href="https://blog.finxter.com/solidity/" data-type="URL" data-id="https://blog.finxter.com/solidity/" target="_blank" rel="noreferrer noopener">Solidity</a> source code (I’ll use <code>1_Storage.sol</code> from the <a href="https://blog.finxter.com/smart-contracts-and-evm/" data-type="post" data-id="92507" target="_blank" rel="noreferrer noopener">Remix contracts</a> folder by creating an empty <a href="https://blog.finxter.com/layout-of-a-solidity-source-file/" data-type="post" data-id="455693">f</a><a href="https://blog.finxter.com/layout-of-a-solidity-source-file/" data-type="post" data-id="455693" target="_blank" rel="noreferrer noopener">i</a><a href="https://blog.finxter.com/layout-of-a-solidity-source-file/" data-type="post" data-id="455693">le</a> and pasting the content into it):</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ mkdir ~/solidity_src/ && cd ~/solidity_src/
$ touch 1_Storage.sol
</pre>
<p><strong>Second</strong>: You can write your own contract for testing purposes or just open the <code>1_Storage.sol</code> with your favorite <a href="https://blog.finxter.com/how-to-edit-a-text-file-in-windows-powershell/" data-type="post" data-id="236823" target="_blank" rel="noreferrer noopener">text editor</a> and paste the contents from <code>1_Storage.sol</code> example in Remix.</p>
<p><strong>Third</strong>: Run a Docker container (we already have the image so the download procedure will be skipped); command flag <code>-v</code> mounts our local <code>~/solidity_src</code> directory to the container’s path <code>/sources</code>, path <code>ethereum/solc:stable</code> selects the Docker image to run a container, command flag <code>-o</code> sets the output location for the compiled files, <code>--abi</code> and <code>--bin</code> activate the generation of both <code>.abi</code> and <code>.bin</code> files, and the path <code>/sources/1_Storage.sol</code> selects the source file for compilation:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ docker run -v ~/solidity_src:/sources ethereum/solc:stable -o /sources/output – abi – bin /sources/1_Storage.sol
Compiler run successful. Artifact(s) can be found in directory "/sources/output".
</pre>
<p>When checking our <code>solidity_src</code> directory, we’ll discover a new directory output, created by the Solidity compiler, containing both <code>.abi</code> and <code>.bin</code> files.</p>
<p>Docker also enables us to use the standard JSON interface, and it is a recommended approach when using the compiler with a toolchain. This interface doesn’t require mounted directories if the JSON input is self-contained, in other words, all the code is already contained in the source files and there are no references to external, imported files:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">docker run ethereum/solc:stable – standard-json < input.json > output.json</pre>
<p>Since we haven’t done any examples using the JSON interface, we’ll suspend this approach until a later time.</p>
<h2><a></a>Conclusion</h2>
<p>This article introduced us to a Solidity-supporting technology called Docker. </p>
<p>Of course, our main focus is on an ecosystem consisting of <a href="https://blog.finxter.com/introduction-to-smart-contracts-and-solidity/" data-type="post" data-id="445145" target="_blank" rel="noreferrer noopener">Solidity</a>, <a href="https://blog.finxter.com/smart-contracts-and-evm/" data-type="post" data-id="92507" target="_blank" rel="noreferrer noopener">Ethereum</a>, <a href="https://blog.finxter.com/how-much-does-a-blockchain-engineer-make/" data-type="post" data-id="161686" target="_blank" rel="noreferrer noopener">blockchain technology</a>, etc., but I recognized an opportunity of making a detour and walking us through the process of setting up and using the Solidity compiler via the Docker platform. Therefore, although initially unplanned, we’re also gaining some <a href="https://blog.finxter.com/top-20-skills-of-a-devops-engineer/" data-type="post" data-id="332626" target="_blank" rel="noreferrer noopener">DevOps skills</a>.</p>
<p>In the first and only chapter (yeah, I’m a bit surprised as well) we’ve set the mining charges by getting to know what Docker is. Then we blew a big piece of rock away by discovering how to install Docker on Ubuntu Linux (and by extension, some other operating systems). I believe this article will prove useful and provide multiple tips and tricks in terms of setting your development environment for Solidity on Ubuntu Linux. Besides that and personally speaking, it was always useful to gain secondary knowledge whenever I learned a specific topic, and I’m sure you’ll have the same experience.</p>
<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f30d.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Recommended Tutorial</strong>: <a href="https://blog.finxter.com/solidity-crash-course/" data-type="post" data-id="445146" target="_blank" rel="noreferrer noopener">Solidity Crash Course</a> (by Matija)</p>
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<h2><a href="https://academy.finxter.com/university/solidity-basics/" target="_blank" rel="noreferrer noopener" title="https://academy.finxter.com/university/solidity-basics/">Learn Solidity Course</a></h2>
<p>Solidity is the programming language of the future.</p>
<p>It gives you the rare and sought-after superpower to program against the “Internet Computer”, i.e., against decentralized Blockchains such as <em>Ethereum</em>, <em>Binance Smart Chain</em>, <em>Ethereum Classic</em>, <em>Tron</em>, and <em>Avalanche </em> – to mention just a few Blockchain infrastructures that support Solidity.</p>
<p>In particular, Solidity allows you to<em> create smart contracts</em>, i.e., pieces of code that automatically execute on specific conditions in a completely decentralized environment. For example, smart contracts empower you to create your own <em>decentralized autonomous organizations</em> (DAOs) that run on Blockchains without being subject to centralized control.</p>
<p>NFTs, DeFi, DAOs, and Blockchain-based games are all based on smart contracts.</p>
<p><a href="https://academy.finxter.com/university/solidity-basics/" target="_blank" rel="noreferrer noopener" title="https://academy.finxter.com/university/solidity-basics/">This course</a> is a simple, low-friction introduction to creating your first smart contract using the Remix IDE on the Ethereum testnet – without fluff, significant upfront costs to purchase ETH, or unnecessary complexity.</p>
<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><a href="https://academy.finxter.com/university/solidity-basics/" target="_blank" rel="noopener"><img loading="lazy" src="https://blog.finxter.com/wp-content/uploads/2021/10/image-121.png" alt="" class="wp-image-37299" width="491" height="287" srcset="https://blog.finxter.com/wp-content/uploads/2021/10/image-121.png 982w, https://blog.finxter.com/wp-content/uplo...00x175.png 300w, https://blog.finxter.com/wp-content/uplo...68x448.png 768w" sizes="(max-width: 491px) 100vw, 491px" /></a></figure>
</div>
</div>
https://www.sickgaming.net/blog/2022/08/...on-ubuntu/