我想将文件从主机复制到容器然后执行它。像这样:
docker run --name ubuntu_trusty ubuntu:14.04
docker cp ./script.sh ubuntu_trusty:/script.sh
# run ubuntu_trusty container then execute /bin/bash /script.sh
我可以看到ubuntu_trusty容器
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
20e54389340e ubuntu:14.04 "/bin/bash" 9 minutes ago Exited (0) 1 seconds ago ubuntu_trusty
但我不知道如何重新运行"我的" / bin / bash /script.sh"在里面。怎么做?
答案 0 :(得分:1)
您可以像这样使用docker exec:
$ docker exec -it ubuntu_trusty bash
>>> /script.sh
>>> exit
$ docker exec ubuntu_trusty bash /script.sh
答案 1 :(得分:0)
要完成kev答案作为完全正常的答案,容器必须在使用run
时运行,因此我们必须docker run -i -d --name ubuntu_trusty ubuntu:14.04 /bin/bash
容器并使用 -d 保持其活着:
cp
然后我们可以exec
和docker cp script.sh ubuntu_trusty:/script.sh
docker exec ubuntu_trusty /bin/bash /script.sh
Hello world
SELECT usr.*, userSex.*, city.*
FROM users usr
JOIN user_sex userSex
ON usr.id = userSex.user_id
JOIN cities city
ON usr.user_city = city.city_id
WHERE id = 1