Docker Community Forums

Share and learn in the Docker community.

Run command with sudo in container


(alter) #1

Hi, I don’t understand how to run in a right way command inside container under specific user.
First, I made own ubuntu image with all updates and necessary software
Second, I made own Elasticsearch image base on my 1st image(just add ppa and install elastic)
Third, I’ve created docker-compose.yml:

at-elastic:
  restart: always
  image: localhost:5000/at-elastic:v3 
  ports:
    - 9200:9200
    - 9300:9300
  user: elasticsearch
  command: /usr/share/elasticsearch/bin/elasticsearch -Des.pidfile=/var/run/elasticsearch/elasticsearch.pid -Des.default.path.home=/usr/share/elasticsearch -Des.default.path.logs=/opt/logs -Des.default.path.data=/opt/data -Des.default.path.conf=/etc/elasticsearch
  volumes:
    - /opt/docker/dockerfiles/elasticsearch/data/:/opt/data
    - /opt/docker/dockerfiles/elasticsearch/logs/:/opt/logs
    - /opt/docker/dockerfiles/elasticsearch/conf/:/etc/elasticsearch

But when I run it, I don’t get running elastic, but If I run image in interactive mode and run elastic with the same command manually - everything works fine.
BTW, I tried without option user and my command was:

command: bash -c “sudo -u elasticsearch /usr/share/elasticsearch/bin/elasticsearch -Des.pidfile=/var/run/elasticsearch/elasticsearch.pid -Des.default.path.home=/usr/share/elasticsearch -Des.default.path.logs=/opt/logs -Des.default.path.data=/opt/data -Des.default.path.conf=/etc/elasticsearch”


(alter) #2

I’m sorry, USER option really works, there was another issue, topic should be closed.