Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape character in Docker command line

Tags:

docker

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...

like image 756
avianey Avatar asked Oct 09 '14 08:10

avianey


People also ask

Is it possible to escape a docker container?

Mounted Docker Socket EscapeIf somehow you find that the docker socket is mounted inside the docker container, you will be able to escape from it. This usually happen in docker containers that for some reason need to connect to docker daemon to perform actions.

How do you escape the docker exec?

docker exec You can leave the container with exit or ctrl-D .

How do you exit a docker container in Terminal?

Just Stopping the Container If you want to stop and exit the container, and are in an interactive, responsive shell - press ctrl+d to exit the session. You could as well type the exit command. TL;DR: press ctrl+c then ctrl+d - that means, keep the ctrl key pressed, type a c, and let go of ctrl.

What is Workdir in Dockerfile?

WORKDIR instruction is used to set the working directory for all the subsequent Dockerfile instructions. Some frequently used instructions in a Dockerfile are RUN, ADD, CMD, ENTRYPOINT, and COPY. If the WORKDIR is not manually created, it gets created automatically during the processing of the instructions.


1 Answers

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...

like image 80
avianey Avatar answered Sep 19 '22 06:09

avianey