我正在尝试在 Docker 容器中运行测试,以下是我的 gitlab-ci.yml
image: openjdk:11
include:
- project: 'xxxxxxx/sdlc'
file: '/sdlc.yml'
services:
- docker:dind
gradle test:
stage: test
image: docker:latest
script:
- ls -la
- docker run -t --rm
-v /var/run/docker.sock:/var/run/docker.sock
-v "$(pwd)":"$(pwd)"
-w "$(pwd)"
-u 0:0
openjdk:11 ls -la
在我的脚本中,我使用“ls -la”作为我的第一个命令来列出当前目录中可用的内容,如果在下一步中当前目录作为卷安装在容器内,它应该列出相同的内容。但我什么也没看到。有人可以指出我做错了什么吗?
$ ls -la
total 1752
drwxrwxrwx 9 root root 4096 May 16 21:59 .
drwxrwxrwx 4 root root 4096 May 16 21:59 ..
drwxrwxrwx 6 root root 4096 May 16 21:59 .git
-rw-rw-rw- 1 root root 182 May 16 21:59 .gitignore
-rw-rw-rw- 1 root root 787 May 16 21:59 .gitlab-ci.yml
-rw-rw-rw- 1 root root 4406 May 16 21:59 README.md
-rw-rw-rw- 1 root root 5351 May 16 21:59 build.gradle
-rw-rw-rw- 1 root root 9176 May 16 21:59 checkstyle-config.xml
drwxrwxrwx 2 root root 4096 May 16 21:59 docker
drwxrwxrwx 4 root root 4096 May 16 21:59 dto
drwxrwxrwx 3 root root 4096 May 16 21:59 gradle
-rwxrwxrwx 1 root root 5296 May 16 21:59 gradlew
-rw-rw-rw- 1 root root 2260 May 16 21:59 gradlew.bat
drwxrwxrwx 2 root root 4096 May 16 21:59 project
-rw-r--r-- 1 root root 1612517 May 16 21:59 sdlc_enforcer
drwxr-xr-x 3 root root 4096 May 16 21:59 sdlc_enforcer_dir
-rw-rw-rw- 1 root root 48 May 16 21:59 settings.gradle
drwxrwxrwx 4 root root 4096 May 16 21:59 src
-rw-rw-rw- 1 root root 771 May 16 21:59 whitesource-fs-agent.config
$ docker run -t --rm -v /var/run/docker.sock:/var/run/docker.sock -v "$(pwd)":"$(pwd)" -w "$(pwd)" -u 0:0 openjdk:11 ls -la
Unable to find image 'openjdk:11' locally
11: Pulling from library/openjdk
c5e155d5a1d1: Already exists
221d80d00ae9: Already exists
4250b3117dca: Already exists
3b7ca19181b2: Already exists
1eadaf4c0dff: Already exists
3541530b8726: Pulling fs layer
b5e4c938e30a: Pulling fs layer
a116edcafe05: Pulling fs layer
adf32feffaff: Pulling fs layer
adf32feffaff: Waiting
a116edcafe05: Verifying Checksum
a116edcafe05: Download complete
3541530b8726: Verifying Checksum
3541530b8726: Download complete
b5e4c938e30a: Verifying Checksum
b5e4c938e30a: Download complete
3541530b8726: Pull complete
b5e4c938e30a: Pull complete
a116edcafe05: Pull complete
adf32feffaff: Verifying Checksum
adf32feffaff: Download complete
adf32feffaff: Pull complete
Digest: sha256:768387c0f1e7ec229bc53bd9a8dabb7b81b84d366cb3954cf00ea8400ecadb01
Status: Downloaded newer image for openjdk:11
total 12
drwxr-xr-x. 2 root root 4096 May 16 19:43 .
drwxr-xr-x. 3 root root 4096 May 16 21:59 ..
Job succeeded
参考资料: https ://www.testcontainers.org/supported_docker_environment/continuous_integration/dind_patterns/