2

I want container with "centos:latest" image to be started and should execute my script. The scripts are copied with docker cp commands.

docker create --name centos1 centos:latest
docker cp . 5db38b908880:/opt   ---> scripts are in current directory, hence .
docker commit centos1 new_centos1  --> now new_centos1 image has scripts

Now I want to start new container with the scripts to be executed: I tried below commands:

docker run -ti --rm --entrypoint "cd /opt && deploy_mediainfo_lambda.sh" new_centos1:latest

docker run -ti --rm new_centos1:latest "cd /opt && deploy_mediainfo_lambda.sh"

Both of above commands failed with:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:296: starting container process caused "exec: \"cd /opt && deploy_mediainfo_lambda.sh\": stat cd /opt && deploy_mediainfo_lambda.sh: no such file or directory": unknown.
ERRO[0000] error waiting for container: context canceled 

if used bash command while starting container, I can run my script using 'execuateble path'/'execuatble name' inside container, but I can not do this while starting container on commandline

docker run -ti --rm new_centos1:latest bash
[root@c34207f3f1c4 /]# ./opt/deploy_mediainfo_lambda.sh 

If used below command, which calls executable directly, it gives path error.

docker run -ti --rm new_centos1:latest "deploy_mediainfo_lambda.sh"

docker: Error response from daemon: OCI runtime create failed: container_linux.go:296: starting container process caused "exec: \"deploy_mediainfo_lambda.sh\": executable file not found in $PATH": unknown.
ERRO[0000] error waiting for container: context canceled 

Also not sure about setting $PATH from commandline while starting the container.

I know, using Dockerfile this is achievable, like:

  1. can set path using ENV,
  2. can copy executables with ADD or COPY
  3. run executables using CMD or ENTRYPOINT

How to achieves it using docker commandline?

7
  • What happens if you pass "/opt/deploy_mediainfo_lambda.sh" as the command? Commented Apr 10, 2018 at 5:45
  • It gives below error: standard_init_linux.go:195: exec user process caused "exec format error" Commented Apr 10, 2018 at 5:46
  • What's the first line of deploy_mediainfo_lambda.sh? Commented Apr 10, 2018 at 5:47
  • Export statement like:export AWS_DEFAULT_OUTPUT=json Commented Apr 10, 2018 at 5:48
  • 2
    The first line should specify an interpreter, e.g. #!/bin/bash. Commented Apr 10, 2018 at 5:49

1 Answer 1

1

Thanks melpomene.

Here is my bash script to automate script execution inside container, after copying them, all using docker commands.

 # Start docker container
docker create --name mediainfo_docker centos:latest
# copy script files
docker cp . mediainfo_docker:/opt
# save container with the new image, which contains all scripts.
docker commit mediainfo_docker mediainfo_docker_with_scripts

# Now run scripts inside docker container
docker run -ti --rm  mediainfo_docker_with_scripts:latest /opt/deploy_mediainfo_lambda.sh

Since deploy_mediainfo_lambda.sh is a script, first line of it is: #!/bin/bash

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.