I see that several varieties of this question have been asked in StackOverflow, but unfortunately, I could not get help from any of them.
I have created a docker container with the following command within an Ubuntu operating system:
docker run --name hasan -it ubuntu:latest bash
Inside the docker image, I set up a new file system. Now, I would like to reach the same container to continue to setup my filesystem inside.
How I can do it?
Thanks,
Access the running container with:
docker exec -it hasan bash
You might want to do the setup within a Dockerfile instead of doing it manually.
Related
I have a little question about docker. Please understand me, I`m elementary level about docker. I'm using CentOS 7 Linux.
When I use docker (images), (espatially dropest(https://dropest.readthedocs.io/en/latest/setup.html#installation) I understand, and download image successfully with code below :
docker pull vpetukhov/dropest:latest
and get start with code below :
docker run -it vpetukhov/dropest
and copy my files to runing with dropest
(Copying files from host to Docker container) with code below :
docker cp ./myfile acb889c0c379:/home/user
and running dropest(the program what I use), after running dropest, copy output files to my linux server.
docker cp acb889c0c379:~/outputFilePath/outputFile.txt ./outputFile.txt
In conclusion: docker run CONTAINER -> copy file to CONTAINER -> running program -> copy outputFile to server.
I just want use 'dropest' program! there is nothing else what I want in Container.
Is there any other option? like:
[myID#server]$docker run [something option] dropest (dropest command with myFiles)(myFiles are located on server)
then obtain outputFiles on server
Please help. Best regards.
Why not just bind-mount your files into your container?
e.g. docker run -v "/path/to/your/files:/files" -ti --rm vpetukhov/dropest:latest /files/
Look at the life cycle about docker container!
I follow this picture to make solve the problem
#Niels Hofmans's answer is really useful for me.
If you are korean, please try visit
here :https://0902.tistory.com/4
and here :https://0902.tistory.com/6?category=675093
first,
docker create -v [path where you want on your server]:[path where you want on your CONTAINER] --name [what you want] -it vpetukhov/dropest
In my case:
docker create -v /home/hanjg/imsi:/home/user/Data_host --name imsi_mount -it vpetukhov/dropest
You don`t have to make imsi folder(directory) and Data_host folder(directory). docker make folder automatically.
docker start imsi_mount
docker attach imsi_mount
Finally, you are enter your CONTAINER and try
cd Data_host
It is same as '/home/hanjg/imsi' on your server! : '/home/hanjg/imsi' repository mount on docker CONTAINER! (in my case vpetukhov/dropest CONTAINER)
Thanks!
I'm running openshift and it does not allow docker containers to run commands as root.
Is there a easy way to check if a custom docker image has commands run by root?
Are you sure this is correct, docker doesn't care what's going on within a VM, and root command would only be able to damage it's own VM.
That said you can open a shell on the image and do some checks
docker run -it gregclinker/boot-docker:1.0.3 /bin/sh
Then you could do:
ps -ef
to check any background processes running and so on.
I am looking for a way to create a Docker volume and put some data on it just before a specific container is started - which needs the configuration on startup.
I do not want to modify the container. I would like to use a vanilla container straight from the Docker Hub.
Any ideas?
Update
I did not mention that all this has to be done in a compose file. If I would do it manually, I could wait for the configuration injecting container to finish.
Absolutely! Just create your volume beforehand, attach it to any container (A base OS like Ubuntu would work great), add your data, and you're good to go!
Create the volume:
docker volume create test_volume
Attach it to an instance where you can add data:
docker run --rm -it --name ubuntu_1 -v test_volume:/app ubuntu /bin/sh
Add some data:
Do this within the container; which you are in from the previous command.
touch /app/my_file
Exit the container:
exit
Attach the volume to your new container:
Of course, replace ubuntu with your real image name.
docker run --rm -it --name ubuntu_2 -v test_volume:/app ubuntu /bin/sh
Verify the data is there:
~> ls app/
my_file
I've been using Dockerfiles so often that I've forgotten how to start up a new one without one.
I was reading https://docs.docker.com/engine/reference/commandline/start/ and ofc it doesn't state how to start up a new one.
docker run -it ubuntu:16.04 bash
A Dockerfile describes a Docker image not a container.
The container is an instance of this image.
If you want to run a container without building an image (which means without creating a Dockerfile), you need to use an existing image on the Docker Hub (link here).
N.B.: The Docker Hub is a Docker online repository, they are more repositories like Quay, Rancher and others.
For example, if you want to test this, you can use the hello-world image found on the Docker Hub: https://hub.docker.com/_/hello-world/.
According to the documentation, to run a simple hello-world container:
$ docker run hello-world
Source: https://hub.docker.com/_/hello-world/
If you don't have the image locally, Docker will automatically pull it
from the web. If you want to manually pull the image you can run the
following command:
$ docker pull hello-world
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Source: https://hub.docker.com/_/hello-world/
docker start is used to start a stopped container which already exists and in stopped state.
If you want to start a new container use docker run instead. For information about docker run please see https://docs.docker.com/engine/reference/commandline/run/
What is the difference between docker run and docker create commands?
I usually use run but sometimes in documentation I see create.
Docker's --help tells
create Create a new container
run Run a command in a new container
Does it mean that run is used when we need to pass a command to a new container? What's the aim of create then?
docker run = docker create + docker start.
From docker documentation
The docker create command creates a writeable container layer over the
specified image and prepares it for running the specified command. The
container ID is then printed to STDOUT. This is similar to docker run
-d except the container is never started. You can then use the docker start command to start the container at any point.
This is useful when you want to set up a container configuration ahead
of time so that it is ready to start when you need it. The initial
status of the new container is created.
docker create command creates a writeable container from the image and prepares it for running.
docker run command creates the container (same as docker create) and starts it.
The other answers have this covered but I thought I'd show the equivalent shell command-lines because it makes it really clear:
$ docker run myimage
is the same as
$ docker start -a $(docker create myimage)
Here, docker create is used to create a container from the named image and outputs the created container id and docker start is used to start the container with that id. The -a option causes the terminal to attach so that the container runs in the foreground which is the default behaviour of docker run.
A container that has been created but never started will have a Created status; this can be seen with docker container ls -a.
I'm new to docker and just got around to playing with it;
My take is that docker run essentially does the following: (in the order of..) docker create, docker start, docker attach , since it immediately attaches to the active shell after you do the 'run' command.
to create a container:
to start a container:
to create and start with a single command:
Now to understand we must dig deep with create and start.
Process of creating a container is taking the file system from image, and kind of prep it for use in the new container. When we create the container we are just prepping or setting up the file system snapshot to be used to create the container to actually start the container.
So creating container is about the file system starting it is about actually executing the startup the command.
And to start the container, we actually execute the start up command that might start up the process.
Lets see it in terminal:
When I run command "sudo docker create hello-world" it prints bellow output.
In the output we saw characters printed out. This is the ID of the container that was just created, Now I can actually execute the hello world command inside of this container by running Docker start.
So what happened here, first off we kind of prop the container by getting the file system ready.
Then after that we actually executed the primary start up command in there with Docker start.
-a in the docker start command is for watching output from the container and print it out to your terminal.
So there is very small difference between Docker run and docker start, by default Docker run is going to show you all the logs or all the information coming out of the container. By default Docker start is the opposite Docker start is not going to show you information coming out of the terminal.
Now you know when you need to use Run / Create / Start
Docker run is basically for running commands in the container.
docker run -it <Container Name> /bin/bash
The above is for creating a bash terminal. And make us use bash commands in the container.
Docker create is to create a container from an Docker Image.
docker create -d /var/lib:/var/lib --name docker-ubuntu ubuntu
The above is to create a docker a container of the name "docker-ubuntu" from the image "ubuntu"