18

I have a docker image in which I want to run the following command :

  1. echo "1" > /tmp/service.cfg
  2. /bin/bash

How can I group and escape this command to run it within a docker container :

docker run -i -t debian/latest echo "1" > /tmp/service.cfg && /bin/bash

The command above doesn't works as it doesn't echo in the desired file first and then give me the hand in a shell...

avianey
  • 5,545
  • 3
  • 37
  • 60

1 Answers1

29

I found the solution, I needed to run the sh command with the -c flag like this :

docker run -i -t debian:latest sh -c 'echo "1" > /tmp/service.cfg && cat /tmp/service.cfg'

This returns 1 as expected...

avianey
  • 5,545
  • 3
  • 37
  • 60