Ssh – command not found when using docker container

dockergitlabssh

I use a docker container in my gitlab ci to login into a server via ssh. When I login into the server via my computer is it possible to run php70 or /usr/bin/php71 without errors. Also there is the typical user@pc:path on the left side.

When I use the ssh client in the docker container and I'm logged in into the server there is only "$" and no user@pc:path and commands like php70 or /usr/bin/php71 are not found. My first idea was ,that I use a diferent shell but echo $SHELL is at both /bin/bash. My gitlab-ci.yml code is this:

image: ruby:2.1
  stage: on_server
  environment: production
  before_script:
    # install ssh-agent
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'

    # run ssh-agent
    - eval $(ssh-agent -s)

    # add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
    - ssh-add <(echo "$SSH_KEY_PRIVATE")

    # disable host key checking (NOTE: makes you susceptible to man-in-the-middle attacks)
    # WARNING: use only in docker container, if you use it with shell you will overwrite your user's ssh config
    - mkdir -p ~/.ssh
    - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config

  script:
    - ssh $SSH_USER_PRODUCTION@$FTP_HOST_PRODUCTION "bash -l"
    - bash
    - echo $SHELL
    - echo $PATH
    - SYMFONY_ENV=prod php71 composer.phar install --no-dev --optimize-autoloader --ignore-platform-reqs
    - SYMFONY_ENV=prod php71 app/console doctrine:migrations:migrate
    - SYMFONY_ENV=prod php71 app/console cache:clear --env=prod

Does anybody know where this behavoir came from?

Best Answer

Are you ssh'ing in as the same user as typical?

Are you ssh'ing into the same machine you or on or to a remote one?

What OS are you running? Assuming *Nix...

Run whoami, groups and echo $PATH (individually of course).

If the binaries are not in the PATH variable it is clear why they are not being found.

You need to install the tools for them to be in the container, (if that is what you want). ADD and COPY can work but you need to make sure you install Everything needed. If you need specific tools and are build an image with a Dockerfile then one option is installing them into the image there. You can also set a USER parameter in the Dockerfile, you can also mount volumes.