GithubHelp home page GithubHelp logo

how to use SSH command line about dip HOT 4 CLOSED

bibendi avatar bibendi commented on May 28, 2024
how to use SSH command line

from dip.

Comments (4)

jnicho02 avatar jnicho02 commented on May 28, 2024 1

Heh! Typically, i've just answered my own question.

I added openssh-client to my Dockerfile, and '- ~/.ssh:/root/.ssh:ro' to my volumes. I know that it is not ideal to share my .ssh like this, but the Docker images are not going to be published.

Thanks for listening. Dip has been very helpful in my bid to manage chaos and work almost 100% in Docker, keep up the good work.

from dip.

bibendi avatar bibendi commented on May 28, 2024

Hi Jez!
It seems that I didn't understand your question enough. Please, provide your configs (dip.yml, docker-compose.yml).

dip ssh it's a shourtcut command to run a sidekick container with running ssh-agent which shares SSH_AUTH_SOCK to your main container.

from dip.

jnicho02 avatar jnicho02 commented on May 28, 2024

I'll try to explain what I want to achieve πŸ‘

  • I have a remote Production server that I can ssh into
  • I have run ssh-add, so that is uses my credentials to login
  • I ssh (and sftp) into the server to dump the Production database, copy the dump file to my local machine, and restore the dump to my dev database
  • I wish to do this from within my Docker container (ruby:2.6.6-slim-buster) which does not currently have an 'ssh' command

dip.yml includes the interaction:

interacton:
  livepull:
    description: Pull data from live into development
    service: runner
    command: /bin/bash local_restore.sh

local_restore.sh has the lines:

ssh [email protected] <<EOF
  pg_dump postgres://pg_user:pg_password@localhost:5432/mydb -h localhost --no-acl --no-owner -Fc > mydb_production_$(date +'%Y%m%d').dump
  exit
EOF
sftp [email protected] <<EOF
  get my_db_production_$(date +'%Y%m%d').dump
  exit
EOF
dropdb -h postgres -U postgres my_db_development
createdb -h postgres -U postgres my_db_development
pg_restore -h postgres -U postgres -d my_db_development my_db_production_$(date +'%Y%m%d').dump

Perhaps the SSH that dip has is nothing to do with what I am trying to do? Does 'dip ssh' make it so that you can ssh in to your Docker instance, not out from?

Do you have any pointers? Just install openssh-client?

from dip.

blijblijblij avatar blijblijblij commented on May 28, 2024

fyi @jnicho02

alternatively 1

one could do without ssh altogether and lean on the build in postgres container behaviour, from their docs

Initialization scripts

If you would like to do additional initialization in an image derived from this one, add one or more *.sql, *.sql.gz, or *.sh scripts under /docker-entrypoint-initdb.d (creating the directory if necessary). After the entrypoint calls initdb to create the default postgres user and database, it will run any *.sql files, run any executable *.sh scripts, and source any non-executable *.sh scripts found in that directory to do further initialization before starting the service.

Warning: scripts in /docker-entrypoint-initdb.d are only run if you start the container with a data directory that is empty; any pre-existing database will be left untouched on container startup. One common problem is that if one of your /docker-entrypoint-initdb.d scripts fails (which will cause the entrypoint script to exit) and your orchestrator restarts the container with the already initialized data directory, it will not continue on with your scripts.

For example, to add an additional user and database, add the following to /docker-entrypoint-initdb.d/init-user-db.sh:

#!/bin/bash
set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
    CREATE USER docker;
    CREATE DATABASE docker;
    GRANT ALL PRIVILEGES ON DATABASE docker TO docker;
EOSQL

or

alternatively 2

one can of course also docker exec CONTAINERID COMMAND into the container, or docker-compose exec postgres COMMAND

from dip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.