background

Since I bought the M1 chip Mac, whenever I want to use a software, I need to go to Baidu :” Mac M1 XXX software “, and then carefully scan the search out the entry, afraid to see “XXX software does not support M1” such words…

Fortunately, now the ecology of M1 is gradually improving, this is not, the blogger’s heart of docker has also supported M1, yesterday just used docker to deploy some local often used development software, today immediately to write a blog, while it is hot!

Docker installation

First we need to download a Docker Desktop.

Download address: docs.docker.com/desktop/mac…

Translate for you:

Docker Desktop for Mac on Apple chips is now available as a GA version. This enables you to use your choice of local development environment and extend the development pipeline for ARM-based applications. Docker Desktop for Apple chips also supports multi-platform mirroring, allowing you to build and run x86 and ARM architectures without setting up complex cross-compiled development environments. In addition, you can use Docker Buildx to seamlessly integrate multi-platform builds into your build pipeline, and use Docker Hub to identify and share repositories that serve multi-platform images.

We support Apple chips, please feel free to use them.

After downloading, install, no brainless next step, next step…

After the installation is complete, this interface will appear:

(Of course, the container list in the red box is empty after the installation.)

Docker is now started locally.

We can verify this by using the command line:

docker ps

This shows that your Docker installation is ok.

Now let’s install some of the images we need.

Centos image

In fact, Docker already supported M1 last year, but I didn’t use it very much on M1 because: there was no centos to run on M1 at that time… (Maybe Ubuntu had earlier support for M1, but I use Ubuntu less and haven’t paid much attention to it.)

But now centos has also been released for M1 version.

Docker Hub: Hub.docker.com/

Here we can see the versions of all centos images, which I selected here

Note that the version you choose should only support the ARM architecture.

Now let’s pull the image locally:

docker pull centos:centos7

After pulling to the local, check:

docker images

Then we can run it:

docker run -d -p 5000:22 --name centos7-test --privileged=true centos:centos7 /usr/sbin/init

Establish port mapping of the host’s Centos7 image, and map port 22 of Centos7 in docker to port 5000 of the host.

Then we check to see if the container is started:

Enter the container:

docker exec -it centos7-test /bin/bash

So that’s going inside the container.

Then we can install some common centos tools:

yum install net-tools -y

yum install -y openssh-server vim lrzsz wget gcc-c++ pcre pcre-devel zlib zlib-devel ruby openssl openssl-devel patch bash-completion zlib.i686 libstdc++.i686 lsof unzip zip

yum install initscripts

We can connect to the virtual machine from the outside, but we need to configure SSH first:

  • Edit the SSHD configuration file /etc/ssh/sshd_config and change the value of UsePAM yes to UsePAM no

    • You can go to the sshd_config file or run the sed -i “s/UsePAM.*/UsePAM no/g” /etc/ssh/sshd_config command
  • To create a public and private key, enter the command and press Enter twice

    • ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key

    • ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key

    • ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key

  • To enable the SSH service, run the /usr/sbin/sshd -d & command

  • Check to see if the service is up: ps – ef | grep SSHD

So, let’s use SSH to connect:

Oh hoo! Call it a day!

In this way, our local virtual machine environment, even if the construction is complete, happy to play.

MySql mirror

Development of the most common, than the local build a database, MySql is certainly the first choice.

There are only 8.0+ versions of MySql that can support M1, but it does not affect daily use.

docker pull mysql/mysql-server:latest

After the image is pulled down, run it:

docker run -itd --name mysql_local -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql/mysql-server

Once up and running, we enter the inside of the container:

docker exec -it mysql_local /bin/bash

Then log in to the data using the root account:

mysql -uroot -p123456

So here we are.

You can check the mysql version:

select version();

View database:

show databases;

Mysql > alter database:

use mysql;

View user permissions:

select host from user;

Change root user authorization to allow remote login:

update user set host='%' where user='root';

Refresh database:

flush privileges;

Now we can connect to MySql using an external SQL tool:

Happy to play with databases again.

Redis mirror

Redis’ image deployment is relatively straightforward and mindless.

docker pull redis

Run it:

docker run -itd --name redis -p 6379:6379 redis

Into a container:

docker exec -it redis /bin/bash

Then run the redis-cli command to enter Redis:

Happy to play with Redis again.

At the end

Docker deployment of some common images explained here, the use of more images, and continue to update. Hopefully this article will help you use M1 to tread less pits.