0

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?

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
fibis
  • 21
  • 1
  • 1

2 Answers2

1

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.

eulerworks
  • 161
  • 5
0

You probably should have an image you use for logging in rather than a container - there's likely no reason to leave the container lying around in between uses. Maybe that's what you meant though.

You are asking two questions, one of them about the prompt (controlled by the $PS1 environment variable in bash) and the other about the path ($PATH environment variable).

The two questions are related in that both are usually set by a startup script used by bash. From the bash manual:

   When bash is invoked as an interactive login shell, or as a  non-inter‐
   active  shell with the --login option, it first reads and executes com‐
   mands from the file /etc/profile, if that file exists.   After  reading
   that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
   in that order, and reads and executes commands from the first one  that
   exists  and  is  readable.  The --noprofile option may be used when the
   shell is started to inhibit this behavior.

When running docker, you use the -i parameter to get an interactive session. My guess is that might be all you need to do in order to get your container to behave as expected, but it might also be that you need to copy in an appropriate profile or bashrc file.

Most interactive invocations of docker want to be run like docker run -it --rm repo/image:version .... Think about each of those flags a bit, and especially the significance of the --rm flag, or your next question will be about where all your disk space is going.

mc0e
  • 5,866
  • 18
  • 31