sudo docker run -p 3000:3000 -d --name mca-service myteam/reponame
this is the command i usually using to run the container. i have a folder in /var/log/appLog. i need to mount this directory with the contaner to store my app log file to make it persistent. i tried
sudo docker run -p 3000:3000 -d --name mca-service -v /var/log/appLog:/var/log/appLog:rw --entrypoint myteam/reponame
this command. but it raise some errors. can someone please help me to do this?
Under which user is your container (myteam/reponame) running? If it is not root, you have to change the user and group and the read/write permission of your folder on the host.
Your --entrypoint is empty. Either remove it or use --entrypoint []
Related
How can I run docker commands inside a docker container when the user is not root?
The reason behind this (running as non root) is that the (first) container creates some files on a mounted volume. If the user in the container is root then these files' owner is also root. If I run the container with the same user as on the host system then these files have the correct user and group.
docker run --rm -it -u $(id -u):$(id -g) -v /var/run/docker.sock:/var/run/docker.sock ubuntu /bin/bash
// inside container:
// assume docker binary is available
docker pull alpine
This will not work when run as a non root user giving following error:
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.24/images/create?fromImage=alpine&tag=latest: dial unix /var/run/docker.sock: connect: permission denied
Docker:
docker run -it -u $(id -u):$(id -g) --group-add $(getent group docker | cut -d ':' -f 3) --rm -v /var/run/docker.sock:/var/run/docker.sock docker docker --version
For Docker Compose set group_add under your service and set the env variable:
export DOCKER_GROUP_ID=$(getent group docker | cut -d ':' -f 3);
services:
myservice:
image: docker
group_add:
- ${DOCKER_GROUP_ID}
How can I access files on a shared network drive from docker container?
I tried:
docker run --rm -it --name my_app -v //shared_drive_name:/opt/local/shared_drive my_app:1.0 /bin/bash
Also I tried method mentioned here: Docker add network drive as volume on windows
The directory /opt/local/shared_drive is created but empty. I tried different variations of slashes since the host is win and docker running linux. I am connected to the VPN from the host to access these drives.
I have this script for mounting Windows shared folders in Ubuntu Docker container. You have to copy the script in your image.
Then you should run the container, and after that call these commands:
docker exec container_name mkdir -p %shared folder inside docker path%
docker exec container_name /bin/bash /~path to your script~/mount_folder.sh %username% %password% %network_path% %docker_path%
For instance:
docker exec container_name /bin/bash /~path to your script~/mount_folder.sh "Admin" somePassword //192.168.7.1/shared_folder /data
Script is (mount_folder.sh):
#!/bin/bash
set -e
USERNAME=${1}
PASSWORD=${2}
NETWORK_PATH=${3}
DOCKER_PATH=${4}
mount -t cifs -o rw,username="${USERNAME}",password="${PASSWORD}",vers=3.0,nolock $NETWORK_PATH $DOCKER_PATH
I'm trying to deploy Apache Ignite Web console on Linux(CentOS 7), but to run docker, i have to set host_absolute_path of MongoDB, How to handle it?
<host_absolute_path> is a path on your host machine where MongoDB will create database files. This folder should be created before docker run. Go to Docker->Preferences->File Sharing and create the directory there or use the other way that suits your more.
Can anybody explain step by step?
docker run -d -p 80:80 -v <host_absolute_path>:/var/lib/mongodb --name web-console-standalone apacheignite/web-console-standalone
<host_absolute_path> is just a path on your local machine. MongoDB is embedded into the docker image. You need to specify a path where MongoDB will store data.
It's required because data need to survive restarts of the container. For example you can run:
docker run -it --rm -p 8080:80 -v /home/user/mongodb:/var/lib/mongodb apacheignite/web-console-standalone:2.7.0
It will run Web console 2.7.0 on 8080 port of the host machine and store data in /home/user/mongodb. This directory should be already present when you start the container.
For Windows:
something like below worked
docker run -d -p 80:80 -v D:\Softwares\IgniteProject\MangoDB:/var/lib/mongodb --name web-console-standalone apacheignite/web-console-standalone
Is it difference between this commands?
docker container run -d --name moby-counter --network moby-counter -p 8080:80 russmckendrick/moby-counter
docker run -itd --name moby-counter --network moby-counter -p 9090:80 russmckendrick/moby-counter
In addition then why in second command uses -i(Interactive) and -t(TTY)?
docker container run is equivalent to docker run, as well as nearly all docker container commands can be found without container subset.
About -it. t creates console (tty), and i forwards your input to docker. That means you can use -t when you just need to observe the output, but you need both when container expects some input from you.
I build container with:
docker build -f Dockerfile.xyz -t dave/xyz .
after that I run docker with:
docker run -it \
--env='LDAP_USER=uid=bot_for_git,ou=bots,dc=company,dc=org' \
--env='LDAP_PASS=' --volume=/srv/docker/xyz/data1:/data \
-p 8010:8010 -p 9989:9989 dave/xyz
and verified that's all ok.
what is next?
My guess, that I should run docker ps, take container id from there, and to run container with the same preferences (environment, port mapping, volumes mapping) I should run:
docker start -a container_id
am I right?
And what about rebuilding image, if change Dockerfile.xyz and rebuild dave/xyz, does container with container_id get
update automatically, or I should repeat docker run -it step?
docker build [...] creates an image. You can see your images with docker images. You may give that image a specific name with the --tag=[...] option:
docker build --tag="superuser/bestimage:latest" .
docker run [...] <imageId> takes that image and starts a container. You can see active containers with docker ps (all with docker ps -a). If you used the tag above, docker run -it superuser/bestimage:latest may be used.
When you rebuild an image, a new image with a new id is created. You may see that through docker images.
does container with container_id get update automatically
No. In order to update your container, you must first remove the container with docker kill <id> and then start a new one with docker run -it <newID>.
Your initial guess
docker start -a container_id
is close but to be able to interact with the container's terminal, include the -i option, as follows:
docker start -ai container_id