Reputation: 8843
I want to make a script run a series of commands in a Docker container and then copy a file out. If I use docker run
to do this, I don't get back the container ID, which I would need for the docker cp
. (I could try and hack it out of docker ps
, but that seems risky.)
It seems that I should be able to
docker create
(which returns the container ID).But I don't know how to get step 2. to work. docker exec
only works on running containers...
Upvotes: 1
Views: 1386
Reputation: 14843
If i understood your question correctly, all you need is docker "run
exec
& cp
" -
For example -
Create container with a name --name
with docker run
-
$ docker run --name bang -dit alpine
Run few commands using exec
-
$ docker exec -it bang sh -c "ls -l"
Copy a file using docker cp
-
$ docker cp bang:/etc/hosts ./
Stop the container using docker stop
-
$ docker stop bang
Upvotes: 2
Reputation: 5550
All you really need is Dockerfile
and then build the image from it and run the container using the newly built image. For more information u can refer to
this
A "standard" content of a dockerfile might be something like below:
#Download base image ubuntu 16.04
FROM ubuntu:16.04
# Update Ubuntu Software repository
RUN apt-get update
# Install nginx, php-fpm and supervisord from ubuntu repository
RUN apt-get install -y nginx php7.0-fpm supervisor && \
rm -rf /var/lib/apt/lists/*
#Define the ENV variable
ENV nginx_vhost /etc/nginx/sites-available/default
ENV php_conf /etc/php/7.0/fpm/php.ini
ENV nginx_conf /etc/nginx/nginx.conf
ENV supervisor_conf /etc/supervisor/supervisord.conf
#Copy supervisor configuration
COPY supervisord.conf ${supervisor_conf}
# Configure Services and Port
COPY start.sh /start.sh
CMD ["./start.sh"]
EXPOSE 80 443
Upvotes: 1