Usage: Docker run - docker

I have my Dockerfile setup for dbt-snowflake/dbt-core with all its prerequisites. I also created a group for that docker image and added some users to that group while writing a docker file.
Incase, if some user want to get added to the image and run their own container, is it possible to do it? Instead of editing a dockerfile by adding a user and build it again.
I tried searching for "docker run [options]" command to pass the user name to the image while running up a container and it did not work for me.
Also tried to get commands for rebuilding the same image with adding a new user.
The command i use to run a container for the user already created while building an image.
docker run -itd -p portnumber:portnumber --user --mount --name
Can I use any command to create a user and add them to the existing group in that image?????

Related

Apache/Nifi 1.12.1 Docker Image Issue

I have a Dockerfile based on apache/nifi:1.12.1 and want to expand it like this:
FROM apache/nifi:1.12.1
RUN mkdir -p /opt/nifi/nifi-current/conf/flow
Thing is that the folder isn't created when I'm building the image from Linux distros like Ubuntu and CentOS. Build succeeds, I run it with docker run -it -d --rm --name nifi nifi-test but when I enter the container through docker exec there's no flow dir.
Strange thing is, that the flow dir is being created normally when I'm building the image through Windows and Docker Desktop. I can't understand why is this happening.
I've tried things such as USER nifi or RUN chown ... but still...
For your convenience, this is the base image:
https://github.com/apache/nifi/blob/rel/nifi-1.12.1/nifi-docker/dockerhub/Dockerfile
Take a look at this as well:
This is what looks like at the CLI
Thanks in advance.
By taking a look at the dockerfile provided you can see the following volume definition
Then if you run
docker image inspect apache/nifi:1.12.1
As a result, when you execute the RUN command to create a folder under the conf directory it succeeds
BUT when you run the container the volumes are mounted and as a result they overwrite everything that is under the mountpoint /opt/nifi/nifi-current/conf
In your case the flow directory.
You can test this by editing your Dockerfile
FROM apache/nifi:1.12.1
# this will be overriden, by volumes
RUN mkdir -p /opt/nifi/nifi-current/conf/flow
# this will be available in the container environment
RUN mkdir -p /opt/nifi/nifi-current/flow
To tackle this you could
clone the Dockerfile of the image you use as base one (the one in
FROM) and remove the VOLUME directive manually. Then build it and
use in your FROM as base one.
You could try to avoid adding directories under the mount points specified in the Dockerfile

How to modifiy a file inside docker Image

I pulled a docker image from https://github.com/snowflakedb/SnowAlert.
But after pulling the Image, I don't see any containers running. I used
docker container ls command and it returned no containers.
Now due to some usecase I want to modify a file inside this docker image.
What is the correct way to do it?
Thanks
Here is what resolved my issue.
After pulling the repository from the github I ran below commands
sudo docker images
This will display the names of existing images. Now copy the Image name in which you need to do the modification.
sudo docker run -it <copied_image_name> bash
This will open a bash where all the files are residing. Do the modification where ever it is required then type exit
Copy the container Id from below command
sudo docker ps -a
Now we need to commit the changes into new Image using below command
sudo docker commit <container_id> <new_image_name>
Thats all
Now do sudo docker images this will display the newly created image with the modified content.
Thanks
Don't confuse image with container: https://phoenixnap.com/kb/docker-image-vs-container.
You need to "up" image to create appropriate container for it: https://docs.docker.com/get-started/part2/#run-your-image-as-a-container
If you want to inspect/edit any container use command (it like ssh to container's server):
docker exec -it CONTAINER_ID bash
To get all docker containers and find their IDs use command:
docker ps -a

Can't edit docker images file in host

I am new to docker and I have pulled docker image PredictionIO, I need to edit a file in it and re-run but I can't. docker image is not in my directories, too. how can I save the image to my host and edit it?
I use Ubuntu 17.04
thank you :)
There are 3 approaches to your problem:
Get the Dockerfile and edit it, then build the image yourself.
Run a container from the pulled image.
Then docker exec -it into it and do your modifications.
After that use docker commit <container id> repository/imagename:tag.
Use bind mounts to map the file to a host directory and edit the file, this way you dont even need to modify the image.
In order to do this, you need to specify the mount when creating the container:
mkdir /path/to/host/config/folder
create the required file(s) and then create the container:
docker run -d --name mycontainer -v /path/to/host/config/folder:/path/to/container/config/folder/ <repository>/<image>:<tag> <command>
Please note the -v switch. After this when you exec into container and navigate to /path/to/container/config/folder/ you will see the contents of the /path/to/container/config/folder/.

How can i save the data and softwares inside docker container permanently?

I am using docker image opencv from https://hub.docker.com/r/andrewssobral/bgslibrary_opencv3/
of andrewssobral author.
First, i initialized container of the image by typing command:
docker run -it -p 5901:5901 andrewssobral/bgslibrary_opencv3 bash
And i tried install vim by command line:
apt-get install vim
But when i use exit COMMAND to go out of the container and i run it again then vim was uninstalled.
So how do i install vim or another software permanently inside docker?
But when i exit docker above container and i run it again then vim was uninstalled.
This is where the problem is: docker run creates a new container.
When you use docker run ... a new container is created and started based on the image you provide inside the command. It is also assigned a random name (if you don't specify one). If this container exits, you can then use docker start name and start it again. This means that if you had previously installed vim it will be there.
Solution: create a new image which includes what you need.
#Sergiu proposed to use Dockerfile
or another way is to save the current state of your container to a new image so that you can use it later on to create new containers with your changes included. To do this you can use docker commit
something like this:
docker commit your_modified_container_name [REPOSITORY[:TAG]]
You have two options: or you edit the Dockerfile provided by the author to add vim or you create a new Dockefile FROM the image.

Debug set always restart container docker

How can I debug docker container that I set to always restart.
I have a container that launch nodejs app, with a
CMD ["nodemon", "/usr/src/app/app.js »] that work very well on other container but not on the new one i created it says with docker logs containerName :
Usage: nodemon [nodemon options] [script.js] [args]
See "nodemon --help" for more.
How can I connect to the container to have more informations than logs, for example see some config file or if my nodejs files have been copied.
I didn’t find a way : I would like to use docker exec -it bash and navigate in my docker but because it is always restarting I cannot. How to debug this kind of container ?
EDIT : i use the CMD["bash"] but when i use docker exec -it bash i doesn't work
Because the container keep restarting.
You could make a new image base on your container image, and a different starting script (one which runs the node command for testing, and then opens a bash for instance)
You could need to COPY that script
COPY myscript /usr/local/bin
CMD ["/usr/local/bin/myscript"]
That way, you can test your current image as wrapped in a test image.
You can even only use bash in that new image
CMD["bash"]
And launch the command manually.
For that, you would need to run that image with:
docker run -it --rm myNewImage
That will open an interactive bash session.

Resources