Create an environment where CircleCI can be executed locally with Windows10 + WSL2 (Ubuntu) + Docker

Recently, I was enthusiastic about the Windows environment and WSL (Windows Subsystem for Linux) 2, and I felt that CircleCI was not enough, so I created an environment where I can test CircleCI. It's easy to install except when you're worried that you don't have to install Docker in Linux installed with WSL.

TL;DR

Operating environment

Introduction of WSL (Windows Subsystem for Linux) 2

Use dism.exe to install the Windows subsystem and virtual machine platform for Linux required for WSL. This package will not take effect until ** restart, so ** restart Windows after installation.

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Then install the Linux kernel update package. Install the file downloaded from the link.

https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi

The following command specifies the default version for the newly installed Linux distribution to be installed in WSL2 format.

wsl --set-default-version 2

If you do not do this, the next Linux installation will be installed in WSL1 format.

Introduction of Linux distribution (Ubuntu)

The link at https://aka.ms/wslstore opens a gallery of Linux distributions that you can install in the Microsoft Store. Install Ubuntu from there.

After installation, click Ubuntu from the start menu to start it. ** It will take a few minutes due to the initial setting, but it will start immediately from the next time.

You will be asked for the user name and password to use with Ubuntu, so set them here.

Check if it was introduced in WSL2

When you're done, run the following command on your Windows terminal (Command Prompt / PowerShell) to see a list of your installed Linux distributions.

wsl -l -v

You should see something like this

   NAME                   STATE           VERSION
 * Ubuntu                 Running         2

If VERSION is not 2, it is introduced in WSL1. To convert to VERSION 2, install the "Linux Kernel Update Package" and then set the WSL version to 2 for the Linux installed in WSL1.

wsl --set-version Ubuntu 2

The official documentation states that this VERSION can be changed in both directions.

Ubuntu package update

I will also update the package on the Ubuntu side. First, change the source of the package to the Japanese server so that the update will be faster.

cd /etc/apt
sudo sed -i.bak -e "s/http:\/\/archive\.ubuntu\.com/http:\/\/jp\.archive\.ubuntu\.com/g" sources.list

You can update the Ubuntu package with the following command:

sudo apt update
sudo apt upgrade -y

Introducing Windows Terminal

Ubuntu can be started from the start menu, but with the introduction of Windows Terminal

You can tab the terminals such as, etc. into one window. Starting each terminal is as easy as creating a tab.

Windows Terminal can be installed from the Microsoft Store where Ubuntu is installed.

Introducing Docker Desktop for Windows

Introduce Docker for Docker Desktop for Windows. ** Docker will not be installed on Ubuntu side. ** ** Click Get Docker from the official page below to get the installer. https://hub.docker.com/editions/community/docker-ce-desktop-windows

When you run the installer, the "Enable WSL 2 Windows Features" checkbox should be checked, so check it and continue the installation. When Docker Desktop starts and the tutorial window appears, close it.

You can see that the Docker virtual environment has started up with wsl -l -v from the terminal on the Windows side.

wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu                 Running         2
  docker-desktop-data    Running         2
  docker-desktop         Running         2

You can execute Docker commands from a Windows terminal.

docker run -it hello-world

If you pull any container and start it, it will be registered in the list of docker images.

docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              bf756fb1ae65        10 months ago       13.3kB

The same Dockewr operation can be performed from the Ubuntu side, which should not have been installed separately. You can now run it locally with the CircleCI CLI that uses Docker.

Introducing CircleCI CLI

Work on an Ubuntu device. Install the CircleCI CLI with the following command:

sudo sh -c "curl -fLSs https://circle.ci/cli | bash"

CircleCI account settings

Register your CircleCI account with the CLI. If you do not have a CircleCI account, click Create a new one.

After installing the CircleCI CLI, run circleci setup. When "CircleCI API Token" is displayed, click your icon displayed at the bottom right of the CircleCI dashboard to display User Settings.

image.png

Click Personal API Tokens to display a list of API Tokens. Click Create New Token to create a new one.

image.png

If you enter the name of the newly created API Token, the Token will be displayed, but ** because it cannot be displayed again **, copy it, enter it in the CLI settings earlier, and then close the dialog. Let's do it.

The username is displayed on the CircleCI CLI screen to see if you can communicate using the API Token.

Creating a project for local execution

Local execution of CircleCI requires a Git-managed project. Run git init after creating a new directory to use Git.

mkdir sample-project
cd sample-project
git init

When using Git for the first time on Ubuntu, you need to register the name and email address of the committed user.

Registration example


git config --global user.email "[email protected]"
git config --global user.name "ysd-marrrr"

Create some file to make a Git commit.

echo "Hello World!" > README.md
git add README.md
git commit -m "1st commit"

After committing something with Git, create a CircleCI configuration file.

mkdir .circleci

Create a config.yml in the .circleci directory.

yml:./.circleci/config.yml


version: 2.0
jobs:
  build:
    docker:
      - image: circleci/ruby:2.4.2-jessie-node
    steps:
      - checkout
      - run: echo "Hello World"

You can check the configuration file before running locally. You can see that the configuration file is correct with "Config file at .circleci / config.yml is valid."

circleci config validate

Run it locally when you're ready.

circleci local execute

If Success! Is displayed, it is successful! If you execute docker images here, the CircleCI images used in the series of operations are registered locally.

Check the Docker image from a Windows device

If you execute docker images from a Windows terminal in the same way, CircleCI images will be registered.

docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
circleci/picard     latest              b85648cb1ea4        45 hours ago        94.5MB
hello-world         latest              bf756fb1ae65        10 months ago       13.3kB
circleci/ruby       2.4.2-jessie-node   54898fcdc277        2 years ago         968MB

You can use Docker installed on Windows from Ubuntu! With WSL2 and Docker Desktop for Windows, you don't need to install Docker again on Ubuntu.

reference

Install Windows Subsystem for Linux (WSL) on Windows 10 | Microsoft Docs https://docs.microsoft.com/ja-jp/windows/wsl/install-win10

Use WSL2 as backend for Docker Desktop for Windows | Developers.IO https://dev.classmethod.jp/articles/docker-desktop-for-windows-on-wsl2/

I tried setting up Windows Subsystem for Linux 2 (WSL 2) | Developers.IO https://dev.classmethod.jp/articles/how-to-setup-wsl2/

Installation and initial setup of Ubuntu 18.04 on WSL http://www.aise.ics.saitama-u.ac.jp/~gotoh/HowToInstallUbuntu1804OnWSL.html#toc11

Using CircleCI's Local CLI-CircleCI https://circleci.com/docs/ja/2.0/local-cli/

Recommended Posts

Create an environment where CircleCI can be executed locally with Windows10 + WSL2 (Ubuntu) + Docker
Create Chisel development environment with Windows10 + WSL2 + VScode + Docker
Compiled kotlin with cli with docker and created an environment that can be executed with java
I installed WSL2 without using Microsoft Store and tried to build an environment where Docker can be used
I built an Ubuntu environment on Windows 10 using WSL2.
Create an E2E test environment with Docker x Cypress
Create an AWS IoT EduKit development environment with Ubuntu 20.04 + VirtualBox 6.1
How to create an environment that uses Docker (WSL2) and Vagrant (VirtualBox) together on Windows
[Windows] WSL2 + Ubuntu + Node.js environment construction
Create a Vue3 environment with Docker!
Let's create Ubuntu environment with vmware
Create RUNTEQ's environment with Windows DockerDesktop
Create SolrCloud verification environment with Docker
Create Laravel environment with Docker (docker-compose)
Create Rails 6 + MySQL environment with Docker compose
Environment construction with Docker (Ubuntu20.04) + Laravel + nginx
Create a MySQL environment with Docker from 0-> 1
Create Spring Boot-gradle-mysql development environment with Docker
[Docker] Create Node.js + express + webpack environment with Docker
Build an environment with Docker on AWS
[Memo] Create a CentOS 8 environment easily with Docker
Self-hosting with Docker of AuteMuteUs in Windows environment
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
Create ubuntu20.04 (or windows10) + anaconda + pytorch or tensorflow environment
Create Spring Boot environment with Windows + VS Code
Build mecab (NEologd dictionary) environment with Docker (ubuntu)
[Rails] How to build an environment with Docker
[First team development ②] Build an environment with Docker
Create a Spring Boot development environment with docker
Build an environment of Ruby2.7.x + Rails6.0.x + MySQL8.0.x with Docker
Range where variables can be used with ruby [Scope]
[Note] Create a java environment from scratch with docker
Build Java development environment with WSL2 Docker VS Code
Comfortable Docker environment created with WSL2 CentOS7 and Docker Desktop