Reputation: 2858
I'm new to Docker and may not understand something.
I have an app
container and a dockerfile
.
I want to install an ssh-client
into the app
container.
I want to be able to run ssh
command to reach some external ip from the app
container.
The simplest way I know is to add
RUN apk update && apk add openssh-client bash
to my dockerfile
, but I'd like to use some ready image, so all my containers could use the same one.
Is it possible to do so?
Upvotes: 3
Views: 13071
Reputation: 2263
Write a Dockerfile
(https://docs.docker.com/engine/reference/builder/):
FROM alpine:latest
# install ssh-client and bash
RUN apk --no-cache add openssh-client bash
# example ssh usage to print version
ENTRYPOINT ["ssh", "-V"]
Build and run it with: docker build -t ssh . && docker run -t ssh ssh
Or use Docker-Compose.
After building with docker build
you can reuse the ssh Docker image in your other projects in Dockerfiles.
FROM ssh
...
Using Docker-Compose docker-compose.yml
:
version: '3'
services:
ssh:
build: .
image: ssh
You can add multiple services in the compose file as you like. The docker compose file from above uses the Dockerfile from above to build your ssh docker image. See the compose file reference: https://docs.docker.com/compose/compose-file/
Upvotes: 4
Reputation: 51758
If you search over dockerhub where all the public images reside, you will find that all the "ssh-client" popular images there are simply building on top of alpine and installing openssh-client
exactly that way you described it.
So there is no obvious benefit in using those existing images. Just install the ssh-client via:
RUN apk update && apk-install openssh-client
Upvotes: 3