"docker pull" 使用 Gitlab Runner 部署到 Digital Ocean 时 requires exactly 1 argument 错误
"docker pull" requires exactly 1 argument error when using Gitlab Runner to deploy to Digital Ocean
晚上好,
我正在尝试部署我的 nodejs 应用程序并使用 pm2 使其 运行 并使用 Docker,但 Docker 抛出“”docker pull” 正好需要 1 个参数。
参见 'docker pull --help'。
用法:docker pull [OPTIONS] NAME[:TAG|@DIGEST]
从注册表中拉取图像或存储库”错误。
感谢您的帮助,感谢您的宝贵时间。
# ssh-keyscan gitlab.com >> authorized_keys: use this command to add gitlab ssh keys to sever. Run on server terminal
# cat id_rsa.pub >> authorized_keys Run this command on the sever on the terminal.
# Both COMMANDS ABOVE ARE necessary.
stages:
- build
- publish
- deploy
variables:
TAG_LATEST: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:latest
TAG_COMMIT: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:$CI_COMMIT_SHORT_SHA
build-Node:
image: node:latest
stage: build
script:
- npm install
- echo "ACCOUNT_SID=$ACCOUNT_SID" >> .env
- echo "AUTH_TOKEN=$AUTH_TOKEN" >> .env
- echo "API_KEY=$API_KEY" >> .env
- echo "API_SECRET=$API_SECRET" >> .env
- echo "PHONE_NUMBER=$PHONE_NUMBER" >> .env
- echo "sengrid_api=$sengrid_api" >> .env
build-Docker:
image: docker:latest
stage: build
services:
- docker:dind
script:
- docker build . -t $TAG_COMMIT -t $TAG_LATEST
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
- docker push $TAG_COMMIT
- docker push $TAG_LATEST
deploy:
image: ubuntu:latest
stage: deploy
tags:
- deployment
before_script:
##
## Install ssh-agent if not already installed, it is required by Docker.
## (change apt-get to yum if you use an RPM-based image)
##
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'
##
## Run ssh-agent (inside the build environment)
##
- eval $(ssh-agent -s)
##
## Create the SSH directory and give it the right permissions
##
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
##
## Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
## We're using tr to fix line endings which makes ed25519 keys work
## without extra base64 encoding.
## https://gitlab.com/gitlab-examples/ssh-private-key/issues/1#note_48526556
##
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- echo "$SSH_PUBLIC_KEY" | tr -d '\r' > ~/.ssh/id_rsa.pub
- chmod 600 ~/.ssh/*
- chmod 644 ~/.ssh/*.pub
- ssh-add
##
## Use ssh-keyscan to scan the keys of your private server. Replace gitlab.com
## with your own domain name. You can copy and repeat that command if you have
## more than one server to connect to.
##
- ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- ls -ld ~/.ssh/*
- cat ~/.ssh/*
##
## Alternatively, assuming you created the SSH_SERVER_HOSTKEYS variable
## previously, uncomment the following two lines instead.
##
#- echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts'
#- chmod 644 ~/.ssh/known_hosts
##
## You can optionally disable host key checking. Be aware that by adding that
## you are suspectible to man-in-the-middle attacks.
## WARNING: Use this only with the Docker executor, if you use it with shell
## you will overwrite your user's SSH config.
##
#- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
##
## Optionally, if you will be using any Git commands, set the user name and
## email.
##
script:
- ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY"
- ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP 'docker pull $TAG_COMMIT'
- ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP 'docker container rm -f my-app || true'
- ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP 'docker run -d -p 80:3000 --name my-app $TAG_COMMIT'
- ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP '. /etc/profile; pm2 reload all'
environment:
name: production
url: http://167.172.225.124
only:
- master
FROM node:12.18.3
# make the starting directory the current one
WORKDIR /
# COPY Package.json
COPY package*.json /
# install the dependencines within the app
RUN npm install
# Install pm2
RUN npm install pm2 -g
# Copy Source Code
COPY . .
# Have docker container use port 3000, that is the port that the node app is set to
EXPOSE 3000
# Start the node app
CMD ["pm2-runtime", "./bin/www"]
错误信息:
"docker pull" requires exactly 1 argument
表示行:
ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP 'docker pull $TAG_COMMIT'
不正确。
- 要么
$TAG_COMMIT
为空(因此没有参数传递给 docker pull
)
- 或
$TAG_COMMIT
中有一个 space(使其 两个 参数传递给 docker pull
- 或
$TAG_COMMIT
未被其值替换并在 ssh 'docker pull $TAG_COMMIT'
会话中保持为空。
使用双引号会有所帮助 (ssh "docker pull $TAG_COMMIT"
),确保 shell 在 发送到远程 shell 之前可以解释 $TAG_COMMIT
。
我会仔细检查(回显)以下值:
TAG_COMMIT: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:$CI_COMMIT_SHORT_SHA
- 该变量的每个分量(
$CI_REGISTRY_IMAGE
、...)
这样,我就能明白为什么传递给 docker pull
的参数不正确了。
晚上好, 我正在尝试部署我的 nodejs 应用程序并使用 pm2 使其 运行 并使用 Docker,但 Docker 抛出“”docker pull” 正好需要 1 个参数。 参见 'docker pull --help'。 用法:docker pull [OPTIONS] NAME[:TAG|@DIGEST] 从注册表中拉取图像或存储库”错误。 感谢您的帮助,感谢您的宝贵时间。
# ssh-keyscan gitlab.com >> authorized_keys: use this command to add gitlab ssh keys to sever. Run on server terminal
# cat id_rsa.pub >> authorized_keys Run this command on the sever on the terminal.
# Both COMMANDS ABOVE ARE necessary.
stages:
- build
- publish
- deploy
variables:
TAG_LATEST: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:latest
TAG_COMMIT: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:$CI_COMMIT_SHORT_SHA
build-Node:
image: node:latest
stage: build
script:
- npm install
- echo "ACCOUNT_SID=$ACCOUNT_SID" >> .env
- echo "AUTH_TOKEN=$AUTH_TOKEN" >> .env
- echo "API_KEY=$API_KEY" >> .env
- echo "API_SECRET=$API_SECRET" >> .env
- echo "PHONE_NUMBER=$PHONE_NUMBER" >> .env
- echo "sengrid_api=$sengrid_api" >> .env
build-Docker:
image: docker:latest
stage: build
services:
- docker:dind
script:
- docker build . -t $TAG_COMMIT -t $TAG_LATEST
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
- docker push $TAG_COMMIT
- docker push $TAG_LATEST
deploy:
image: ubuntu:latest
stage: deploy
tags:
- deployment
before_script:
##
## Install ssh-agent if not already installed, it is required by Docker.
## (change apt-get to yum if you use an RPM-based image)
##
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'
##
## Run ssh-agent (inside the build environment)
##
- eval $(ssh-agent -s)
##
## Create the SSH directory and give it the right permissions
##
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
##
## Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
## We're using tr to fix line endings which makes ed25519 keys work
## without extra base64 encoding.
## https://gitlab.com/gitlab-examples/ssh-private-key/issues/1#note_48526556
##
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- echo "$SSH_PUBLIC_KEY" | tr -d '\r' > ~/.ssh/id_rsa.pub
- chmod 600 ~/.ssh/*
- chmod 644 ~/.ssh/*.pub
- ssh-add
##
## Use ssh-keyscan to scan the keys of your private server. Replace gitlab.com
## with your own domain name. You can copy and repeat that command if you have
## more than one server to connect to.
##
- ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- ls -ld ~/.ssh/*
- cat ~/.ssh/*
##
## Alternatively, assuming you created the SSH_SERVER_HOSTKEYS variable
## previously, uncomment the following two lines instead.
##
#- echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts'
#- chmod 644 ~/.ssh/known_hosts
##
## You can optionally disable host key checking. Be aware that by adding that
## you are suspectible to man-in-the-middle attacks.
## WARNING: Use this only with the Docker executor, if you use it with shell
## you will overwrite your user's SSH config.
##
#- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
##
## Optionally, if you will be using any Git commands, set the user name and
## email.
##
script:
- ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY"
- ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP 'docker pull $TAG_COMMIT'
- ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP 'docker container rm -f my-app || true'
- ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP 'docker run -d -p 80:3000 --name my-app $TAG_COMMIT'
- ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP '. /etc/profile; pm2 reload all'
environment:
name: production
url: http://167.172.225.124
only:
- master
FROM node:12.18.3
# make the starting directory the current one
WORKDIR /
# COPY Package.json
COPY package*.json /
# install the dependencines within the app
RUN npm install
# Install pm2
RUN npm install pm2 -g
# Copy Source Code
COPY . .
# Have docker container use port 3000, that is the port that the node app is set to
EXPOSE 3000
# Start the node app
CMD ["pm2-runtime", "./bin/www"]
错误信息:
"docker pull" requires exactly 1 argument
表示行:
ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP 'docker pull $TAG_COMMIT'
不正确。
- 要么
$TAG_COMMIT
为空(因此没有参数传递给docker pull
) - 或
$TAG_COMMIT
中有一个 space(使其 两个 参数传递给docker pull
- 或
$TAG_COMMIT
未被其值替换并在ssh 'docker pull $TAG_COMMIT'
会话中保持为空。
使用双引号会有所帮助 (ssh "docker pull $TAG_COMMIT"
),确保 shell 在 发送到远程 shell 之前可以解释$TAG_COMMIT
。
我会仔细检查(回显)以下值:
TAG_COMMIT: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:$CI_COMMIT_SHORT_SHA
- 该变量的每个分量(
$CI_REGISTRY_IMAGE
、...)
这样,我就能明白为什么传递给 docker pull
的参数不正确了。