Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to find user root: no matching entries in passwd file in Docker

I have containers for multiple Atlassian products; JIRA, Bitbucket and Confluence. When I'm trying to access the running containers I'm usually using:

docker exec -it -u root ${DOCKER_CONTAINER} bash

With this command I'm able to access as usual, but after running a script to extract and compress log files, I can't access that one container anymore.

Excerpt from the 'clean up script'

This is the first point of failure, and the script is running once each week (scheduled by Jenkins).

docker cp ${CLEAN_UP_SCRIPT} ${DOCKER_CONTAINER}:/tmp/${CLEAN_UP_SCRIPT}
if [ $? -eq 0 ]; then
  docker exec -it -u root ${DOCKER_CONTAINER} bash -c "cd ${LOG_DIR} && /tmp/compressOldLogs.sh ${ARCHIVE_FILE}"
fi

When the script executes these two lines towards the Bitbucket container the result is:

unable to find user root: no matching entries in passwd file

It's failing on the 'docker cp'-command, but only towards the Bitbucket container. After the script has ran, the container is unaccessible with both the 'bitbucket' (defined in Dockerfile) and 'root' users.

I was able to copy /etc/passwd out of the container, and it contains all of the users as expected. When trying to access by uid, I get the following error:

rpc error: code = 2 desc = oci runtime error: exec failed: process_linux.go:75: starting setns process caused "fork/exec /proc/self/exe: no such file or directory"

Dockerfile for Bitbucket image:

FROM                        java:openjdk-8-jre

ENV BITBUCKET_HOME          /var/atlassian/application-data/bitbucket
ENV BITBUCKET_INSTALL_DIR   /opt/atlassian/bitbucket
ENV BITBUCKET_VERSION       4.12.0
ENV DOWNLOAD_URL            https://downloads.atlassian.com/software/stash/downloads/atlassian-bitbucket-${BITBUCKET_VERSION}.tar.gz

ARG user=bitbucket
ARG group=bitbucket
ARG uid=1000
ARG gid=1000

RUN mkdir -p $(dirname $BITBUCKET_HOME) \
    && groupadd -g ${gid} ${group} \
    && useradd -d "$BITBUCKET_HOME" -u ${uid} -g ${gid} -m -s /bin/bash ${user}

RUN mkdir -p                                ${BITBUCKET_HOME} \
    && mkdir -p                             ${BITBUCKET_HOME}/shared \
    && chmod -R 700                         ${BITBUCKET_HOME} \
    && chown -R ${user}:${group}            ${BITBUCKET_HOME} \
    && mkdir -p                             ${BITBUCKET_INSTALL_DIR}/conf/Catalina \
    && curl -L --silent                     ${DOWNLOAD_URL} | tar -xz --strip=1 -C "$BITBUCKET_INSTALL_DIR" \
    && chmod -R 700                         ${BITBUCKET_INSTALL_DIR}/ \
    && chown -R ${user}:${group}            ${BITBUCKET_INSTALL_DIR}/

${BITBUCKET_INSTALL_DIR}/bin/setenv.sh

USER        ${user}:${group}

EXPOSE      7990
EXPOSE      7999

WORKDIR     $BITBUCKET_INSTALL_DIR
CMD         ["bin/start-bitbucket.sh", "-fg"]

Additional info:

  • Docker version 1.12.0, build 8eab29e
  • docker-compose version 1.8.0, build f3628c7
  • All containers are running at all times, even Bitbucket works as usual after the issue occurres
  • The issue disappears after a restart of the container
like image 927
Magnus Avatar asked Jan 16 '17 12:01

Magnus


People also ask

How do I get root permission in a docker container?

As an alternative, we can also access the Docker container as root. In this case, we'll use the nsenter command to access the Docker container. To use the nsenter command, we must know the PID of the running container. This allows us to access the Docker container as a root user and run any command to access any file.

What is the root directory of docker?

By default, Docker stores most of its data inside the /var/lib/docker directory on Linux systems.

Can I install docker without root privileges?

Rootless mode allows running the Docker daemon and containers as a non-root user to mitigate potential vulnerabilities in the daemon and the container runtime. Rootless mode does not require root privileges even during the installation of the Docker daemon, as long as the prerequisites are met.


1 Answers

You can use this command to access to the container with root user:

docker exec -u 0 -i -t {container_name_or_hash} /bin/bash

try debug with that. i think the script maybe remove or disable root user.

like image 97
Orbán Zoltán Avatar answered Sep 18 '22 08:09

Orbán Zoltán