docker的基本命令
docker images 镜像列表
docker pull xxx:xx 拉取镜像
docker stop containerName 停止容器
docker rm containerName 删除容器
docker rmi abc 删除镜像,镜像ID三个首字母
1 安装nginx
参考自这里
安装docker:apt install docker.io
下载nginx镜像:docker pull nginx:1.22.0
1.22.0: Pulling from library/nginx
bd159e379b3b: Pull complete
265da2307f4a: Pull complete
9f5a323076dc: Pull complete
1cb127bd9321: Pull complete
20d83d630f2b: Pull complete
e0c68760750a: Pull complete
Digest: sha256:f0d28f2047853cbc10732d6eaa1b57f1f4db9b017679b9fd7966b6a2f9ccc2d1
Status: Downloaded newer image for nginx:1.22.0
docker.io/library/nginx:1.22.0
创建nginx宿主配置文件:mkdir /root/docker-nginx
运行docker:
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 11725/docker-proxy
创建容器并运行:
docker run --name nginx -p 80:80 -d nginx:1.22.0
把nginx内部文件拷贝到宿主:
root@daniel:~# docker cp nginx:/etc/nginx/nginx.conf /root/docker-nginx/
root@daniel:~# docker cp nginx:/etc/nginx/conf.d/ /root/docker-nginx/conf.d/
root@daniel:~# docker cp nginx:/usr/share/nginx/html/ /root/docker-nginx/html/
root@daniel:~# docker cp nginx:/var/log/nginx/ /root/docker-nginx/logs/
将nginx配置文件等打包,以后可以作为模板复用:
tar -czvf docker-nginx.tar.gz docker-nginx/*
停止docker:docker stop nginx
删除容器:docker rm nginx
创建容器并运行:
docker run -p 80:80 \
-v /root/docker-nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /root/docker-nginx/logs:/var/log/nginx \
-v /root/docker-nginx/html:/usr/share/nginx/html \
-v /root/docker-nginx/conf.d:/etc/nginx/conf.d \
-v /etc/localtime:/etc/localtime \
--name nginx \
--restart=always \
-d nginx:1.22.0
2 安装hugo
参考自这里 拉取镜像:docker pull klakegg/hugo:latest-ext
latest-ext: Pulling from klakegg/hugo
b85a868b505f: Pull complete
0dbfd71332b3: Pull complete
76a604ef4c8f: Pull complete
4f4fb700ef54: Pull complete
ca0d4322cdfd: Pull complete
70ef7fb315e3: Pull complete
0a89b068afa8: Pull complete
Digest: sha256:a82da170159c84e5a59a9fd237da8c063bc062c72d6023afd1a4e3a0c40a9b4e
Status: Downloaded newer image for klakegg/hugo:latest-ext
docker.io/klakegg/hugo:latest-ext
root@daniel:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
klakegg/hugo latest-ext 13ef2cb044b7 2 months ago 963MB
建目录:mkdirs -p /root/docker-hugo,进入目录。
下面这个创建命令一直不成功。docker run --rm -it -v $(pwd):/src klakegg/hugo:latest-ext "new site daniel"
于是用下面的:
root@daniel:~/docker-hugo# docker run --rm -it -v $(pwd):/src klakegg/hugo:latest-ext shell
hugo:/src$ hugo new site roadl.com
Congratulations! Your new Hugo site is created in /src/roadl.com.
Just a few more steps and you're ready to go:
1. Download a theme into the same-named folder.
Choose a theme from https://themes.gohugo.io/ or
create your own with the "hugo new theme <THEMENAME>" command.
2. Perhaps you want to add some content. You can add single files
with "hugo new <SECTIONNAME>/<FILENAME>.<FORMAT>".
3. Start the built-in live server via "hugo server".
Visit https://gohugo.io/ for quickstart guide and full documentation.
成功!
创建博文:cd roadl.com && hugo new posts/first_post.md
然后就能启动了,下列是Developer模式:
docker run --rm -it \
-v $(pwd)/roadl.com:/src \
-p 1313:1313 \
klakegg/hugo:latest-ext \
server
后来用了安装包的方式安装了hugo,后台常驻运行的命令行是:
hugo server --watch --renderToDisk &
下载主题:git clone https://github.com/dillonzq/LoveIt.git themes/loveit
备份主题配置以及替换配置:cp config.toml config.toml.bak && cp themes/loveit/config.toml .
引用主题:echo 'theme = "minimal"' >> config.toml
这时就可以访问到网站了:http://39.98.41.150:1313/
后来,使用了yinyang的主题,链接在这里,并对样式进行了一些调整,比如:
- 加了一个线条
- 调整了site-footer的边距等
- 下方露出ICP备案
3 安装与使用docker compose安装gitlab
项目地址在这里,最新版本2.16.0(2023/02/22)
- 在线下载:
参考自这里
sudo curl -L https://get.daocloud.io/docker/compose/releases/download/v2.16.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 425 100 425 0 0 557 0 --:--:-- --:--:-- --:--:-- 557
100 45.4M 100 45.4M 0 0 11.8M 0 0:00:03 0:00:03 --:--:-- 12.2M
命令行相当于这样:sudo curl -L https://get.daocloud.io/docker/compose/releases/download/v2.16.0/docker-compose-`uname -s-
uname -m` -o /usr/local/bin/docker-compose
还有一个地址是:https://github.com/docker/compose/releases/download/v2.16.0/docker-compose-linux-x86_64
- 添加执行权限:
sudo chmod +x /usr/local/bin/docker-compose
在/root/docker-compose/gitlab下编辑脚本文件docker-compose.yml,内容如下:
version: "3.6"
services:
gitlab:
image: gitlab/gitlab-ce:latest
restart: always
privileged: true
ports:
- '2222:80'
- '2443:443'
- '222:22'
volumes:
- '~/data:/var/opt/gitlab'
- '~/logs:/var/log/gitlab'
- '~/config:/etc/gitlab'
然后运行命令,会执行下载,大小大致在1.2G:
$: docker-compose up -d
[+] Running 9/9
⠿ gitlab Pulled 262.4s
⠿ 7608715873ec Pull complete 8.3s
⠿ 26e3792d4953 Pull complete 9.5s
⠿ b0e6776b820f Pull complete 9.6s
⠿ 97eca40a1a01 Pull complete 9.6s
⠿ 371a93e50028 Pull complete 9.7s
⠿ 81fe9f2c4530 Pull complete 9.8s
⠿ 8330753ccbb8 Pull complete 9.8s
⠿ 324228a983f6 Pull complete 259.0s
[+] Running 2/2
⠿ Network gitlab_default Created 0.4s
⠿ Container gitlab-gitlab-1 Started