Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install SCP in Docker container

Tags:

docker

scp

mysql

I am currently playing around with docker to create a PHP development environment. There are several containers (nginx, php7 + data container, mysql + data container, phpmyadmin) running and connected to each other, which is working fine so far. For convenience reasons, I am adding some scripts to the mysql container which can be used by the other developers to:

  • reset the database to the initial database
  • reset the database to a current dump of production database

I provide a development server which pulls a live dump from production system every 15 minutes and places it in a well-known directory. Now I would like to add the second script to the mysql container, which basically does the following:

Use the SSH key of the developer (has been placed in an accessible folder before), connect to the development machine, get the SQL dump and replace the database with this content.

My current problem is that I have no idea how to get the data. I am using the mysql image as base image, inside the container there is no scp or similar available.

The question: How to realise the problem described above? Can I somehow install the scp command in the container? I don't want to rely on scripts running on the actual host because a variety of operating systems are used.

like image 708
waza-ari Avatar asked Dec 16 '16 15:12

waza-ari


People also ask

Can you SCP to docker?

Copy files from your local host to a machine, from machine to machine, or from a machine to your local host using scp . The notation is machinename:/path/to/files for the arguments; in the host machine's case, you don't need to specify the name, just the path.

Can I install Linux on docker?

Once you understand how to pull base Docker Images from the Docker registry, you can now simply pull OS distributions such as Ubuntu, CentOS, etc directly from the Docker hub.

Does docker copy create directory?

If you specify the -L option, docker cp follows any symbolic link in the SRC_PATH . docker cp does not create parent directories for DEST_PATH if they do not exist.


2 Answers

For CentOS and Red Hat, add the below line to your Dockerfile (making sure the USER is still/again root).

RUN yum update -y && yum install -y openssh-clients

And no, the terminating s is not a typo; in contrast to the Ubuntu/Debian world the package name is a plural word.

like image 148
ᴠɪɴᴄᴇɴᴛ Avatar answered Sep 20 '22 14:09

ᴠɪɴᴄᴇɴᴛ


Add the following to your Dockerfile:

RUN apt-get update && apt-get -y install openssh-client

like image 38
Adam Avatar answered Sep 17 '22 14:09

Adam