Docker Community Forums

Share and learn in the Docker community.

How to write file in container

Hi All,

I have container , i run with
" docker container run --name name --restart=always --network=network -v $(pwd):/var/www/html/ -d -p 8080:80 php:5.6.14-apache "
how to i can write image in container ?
i have app and have to upload file to container
thank you

eval is a shell builtin, whereas docker exec requires an external utility to be called, so using eval is not an option.

Instead, invoke a shell executable in the container (bash) explicitly, and pass it the command to execute as a string, via its -c option:

docker exec “app_$i” bash -c “echo ‘server.url=$server_url’ >> /home/app/.app/app.config”
By using a double-quoted string to pass to bash -c, you ensure that the current shell performs string interpolation first, whereas the container’s bash instance then sees the expanded result as a literal, as part of the embedded single-quoted string.

As for your symptoms:

/home/user/.app/app.config: No such file or directory was reported, because the redirection you intended to happen in the container actually happened in your host’s shell - and because dir. /home/user/.app apparently doesn’t exist in your host’s filesystem, the command failed fundamentally, before your host’s shell even attempted to execute the command (bash will abort command execution if an output redirection cannot be performed).

Thus, even though your first command also contained eval, its use didn’t surface as a problem until your second command, which actually did get executed.
exec: “eval”: executable file not found in $PATH happened, because, as stated, eval is not an external utility, but a shell builtin, and docker exec can only execute external utilities.