· Joseph · DevOps  · 3 min read

Install Docker / Docker-compose on CentOS 8

新的一篇文章來講講最近踩的雷,起因手邊有個案子開了一台CentOS 8機器給我,讓我在上面設定docker跟跑起服務。實在跟CentOS很不熟的我決定寫篇備忘錄。

一開始就先開台乾淨的CentOS VM來準備被我玩爛… install centos

Install Docker

然後,讓我慢慢安裝docker。

$ sudo yum update
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
$ sudo yum install docker-ce #可能會遇到`問題一`

問題一:

yum install docker-ce時出現下列訊息:

package docker-ce-3:19.03.5-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed docker requires

可以透過先執行下列指令解決

sudo yum -y install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm

跑完就安裝好了,讓我們start & enable docker

$ sudo systemctl start docker
$ sudo systemctl enable docker
$ sudo systemctl status docker

看看跟我一不一樣。 docker status

我在安裝的時候有把我的user視為administrator,如果你每次都要透過sudo去執行docker的話,請看看問題二

問題二:

每次都要透過sudo docker執行docker或某些指令會回給你Permission denied嗎?

sudo usermod -aG docker $(whoami)

把自己加入docker群組吧(記得要重新登入)

Install docker-compose

很快的透過curl抓取docker-compose的執行檔,然後把他設定+x mode。

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose

OK,docker-compose --version就可以看到版本了

$ docker-compose --version
docker-compose version 1.24.1, build 4667896b

到這邊都好了嗎?接下來你會遇到docker DNS跟防火牆的困擾。

npm ERR! code EAI_AGAIN npm ERR! errno EAI_AGAIN npm ERR! request to https://registry.npmjs.org/xxxxxxx failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org:443 npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2020-02-12T15_32_35_422Z-debug.log

確認一下docker dns: docker dns

docker run busybox ping -c 1 192.203.230.10 可以出去 docker run busybox nslookup google.com 找不到host

8.8.8.8是我VM的dns server

好,把它打通吧。

$ sudo firewall-cmd --zone=trusted --change-interface=docker0
$ sudo firewall-cmd --reload.

把docker0 interface 加入trusted zone,這時候docker nslookup就通了。

有時候你會需要把4243 port也被防火牆允許: sudo firewall-cmd --permanent --zone=trusted --add-port=4243/tcp

有時候你可能需要手動設定docker dns,可以vim編輯/etc/docker/daemon.json:

{
    "dns": ["8.8.8.8", "8.8.4.4"]
}

到這邊就結束了。最後可以跑個隨便的服務,然後透過VM ip & port 連進去(記得要port mapping)。 剛接到案子本來想說沒這麼複雜,沒想到複雜到我要開一台VM實驗,不過也是學了很多centos的東西。


  1. firewall-cmd 指令參考: https://kirby86a.pixnet.net/blog/post/118276362-centos-7-%E4%BD%BF%E7%94%A8firewall-cmd%E6%8C%87%E4%BB%A4
Back to Blog

Related Posts

View All Posts »
Using Firebase and Firestore with NextJS and Docker - Part 1 - Setup firebase in docker

Using Firebase and Firestore with NextJS and Docker - Part 1 - Setup firebase in docker

Last year, I got a case to use firebase and firestore with Next.js. I've been fullstack many years, so I haven't tried to use firebase and firestore. There was a great chance to give it a try. In this article I'll show how to use firebase and firestore in Docker and Next.js. If you don't have backend support, or you don't want to build whole backend, database, and infrastructure, you would probably think this is a useful way.

Switching from vim to Neovim!

Switching from vim to Neovim!

I've been using Vim for a long time and finally switched to Neovim. The initial thought of switching came after the author of VIM passed away in August 2023, as I didn’t have the time to try other editors. After a year, “vibe coding” grew up, so I started thinking how to integrate AI into my editor and surveying how to use AI in Vim, which led to this journey. TOC Main differences Tab vs. Buffer: ref: https://www.reddit.com/r/neovim/comments/13iy0p0/why_some_people_use_buffers_for_tabs_and_not_vim/ In vim, I used vsp or tabnew to open or edit a file and mapped tabprevious command with Tab key to navigate between tabs. However, in Neovim, I used buffer instead of tabs and mapped BufferLineCyclePrev with Shift + h for switching buffers. coc vs. native lsp: I configured many coc settings to support TypeScript and JavaScript language servers, including linting and Prettier on save, go-to definition or reference, and codelens. After using Neovim, I converted all of these settings to nvim-lspconfig and mason, among others. Lua supports: Although I’m not familiar with Lua, it allows me to write more readable configuration files using modules, functions, and tables (objects) for Neovim. AI supports: Vibe coding! I found many plugins to integrate LLMs and finally selected three to use: avante.nvim Let your Neovim be a Cursor AI IDE – it's undergoing rapid iterations and many exciting features will be added successively; it updates almost every day! CodeCompanion CodeCompanion can customize workflows and prompts, and its Action Palette is a really useful tool. gp.nvim GP means GPT Prompt, and it's an Neovim AI plugin. It helps me write prompts through Neovim's cmdline. I usually switch between these plugins, and I'm still thinking about my 'vibe-way' to use them. Because of supporting Ollama LLM, all of them can be used offline. For now, I've used Neovim for three months, and got to know Neovim. In my experience, Neovim is really more productive than vim. Reference AI in Neovim How to set up Neovim for coding React ZazenCodes Neovim Rewrite by Avante + Ollama gemma3:4b ------ For a long time, I relied on Vim for my coding. However, after Bram Moolenaar’s passing in August 2023 – a significant influence in the Vim community – I decided it was time for a change. I began exploring alternative editors, ultimately settling on Neovim. This journey wasn’t just about switching editors; it was about integrating AI into my workflow and redefining my coding experience. Key Differences: Tabs vs. Buffers One of the first things I noticed was the shift from tabs to buffers in Neovim. In Vim, I frequently used vsp or tabnew to open or edit files, navigating between tabs with the Tab key and Tabprevious command. Neovim, however, utilizes buffers, offering a more streamlined approach. I configured BufferLineCyclePrev with Shift + h for seamless buffer switching, alongside nvim-tree/nvim-web-devicons and akinsho/bufferline.nvim. Leveraging Language Servers with coc and nvim-lspconfig I configured many coc settings to support TypeScript and JavaScript language servers, including linting and Prettier on save, go-to definition or reference, and codelens. Recognizing the power of language servers, I then converted all of these settings to nvim-lspconfig and mason.nvim, streamlining my development environment. Lua Configuration for Readability Although I’m relatively new to Lua, it allows me to write more readable configuration files using modules, functions, and tables (objects) for Neovim. Here’s a snippet of my configuration: AI-Powered Productivity with avante.nvim, CodeCompanion, and gp.nvim To truly elevate my coding experience, I integrated several AI plugins. I selected: avante.nvim**: This plugin transforms Neovim into a Cursor AI IDE, undergoing rapid iterations and adding exciting new features daily. CodeCompanion**: This plugin allows for customizable workflows and prompts, with a particularly useful Action Palette. gp.nvim**: (GPT Prompt) – This plugin helps me write prompts through Neovim’s command line interface, leveraging folke/noice.nvim. Because of supporting Ollama LLM, all of these plugins can be used offline. I’m still experimenting with how to best utilize these plugins – a “vibe-way” to coding! Resources for Further Exploration AI in Neovim How to set up Neovim for coding React ZazenCodes Neovim

Set godaddy domain and build hugo on gitlab pages

The idea comes from... I read a blog 將 Github Page 串上自己的域名 on Medium.com, and I thought about my bad experience in setting gitlab pages. I think I have to write a blog now, and let me remember how to set it again. Hugo First, install go and hugo: My system is Ubuntu 19.04, so I follow Go wiki instructions.