docker-compose useradd 告诉我用户已经存在 [英] docker-compose useradd tells me user already exists

查看:105
本文介绍了docker-compose useradd 告诉我用户已经存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 上使用 Docker 和以下 docker 文件:

I am using Docker on Windows with the following docker file:

FROM php:7.4-fpm

ARG uid=1000
ARG user=devuser

USER root
# Install system packages
RUN apt-get update && apt-get install -y apt-transport-https && apt-get install -y git curl zip unzip libicu-dev

# Cleanup apt
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install php extensions
RUN docker-php-ext-install pdo_mysql intl iconv

RUN useradd -G www-data,root -u $uid -d /home/$user $user

RUN mkdir -p /home/$user/.composer && chown -R $user:$user /home/$user

# Install composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

# Copy project files to image
COPY . /var/www

# Set working directory
WORKDIR /var/www

RUN composer install

# Change user
USER $user

docker-compose.yaml

docker-compose.yaml

version: "3.7"

services:

  app:
    container_name: app
    build:
      context: ./
      dockerfile: Dockerfile
    image: php:7.4-fpm
    ports:
      - 9000:9000
    working_dir: /var/www/
    volumes:
      - ./:/var/www
    networks:
      - dev
    depends_on:
      - database


  server:
    container_name: server
    image: nginx:1.21.0-alpine
    ports:
      - 8000:80
    volumes:
      - ./:/var/www
      - ./docker/nginx:/etc/nginx/conf.d
    networks:
      - dev


  database:
    container_name: database
    image: mariadb:10-bionic
    environment:
      MYSQL_ROOT_PASSWORD: root
    networks:
      - dev
    volumes:
      - database-data:/var/lib/mysql

volumes:
  database-data:
networks:
  dev:
    external: true

它在第一次运行时有效,但是当我想进行更改时,出现以下错误.我已经尝试过停止、杀死、关闭所有容器,但没有任何效果.

It worked on the first run but when I wanted to make changes I get the below error. I have already tried stopping, killing, downing all containers but nothing works.

当我运行 docker-compose up --force-recreate --build -d 时,我得到以下输出:

When I run docker-compose up --force-recreate --build -d I get the following output:

 => ERROR [stage-0  5/10] RUN useradd -G www-data,root -u 1000 -d /home/devuser devuser                                                                                  0.4s
------
 > [stage-0  5/10] RUN useradd -G www-data,root -u 1000 -d /home/devuser devuser:
#8 0.354 useradd: user 'devuser' already exists
------
executor failed running [/bin/sh -c useradd -G www-data,root -u $uid -d /home/$user $user]: exit code: 9
ERROR: Service 'app' failed to build : Build failed

为什么会这样?容器不是封装的吗?设置新环境时如何冲突?我已经停止了所有正在运行的容器

Why does this happen? Arent containers encapsulated? How does it conflict when setting up a new environment? I have stoped all running containers

编辑:例如,当我将 uiduser 更改为 1001devuser1 时,它会再次运行一次.

EDIT: When I change uid and user to, for example, 1001 and devuser1 it works again once.

推荐答案

您已将正在构建的图像命名为与基本图像相同的名称:

You've named the image you are building the same as your base image:

image: php:7.4-fpm

这意味着每次运行构建时,您都会添加更多层并从上次构建进行变异,而不是从原始基础映像重新创建.

That means every time you run a build you add more layers and mutate from the last build rather than recreating from the original base image.

解决方法是为您的图像命名为您独有的名称,而不是踩到上游库图像名称.

The fix is to name your image something unique to you, rather than stepping on the upstream library image name.

image: <your_hub_user>/app:latest

然后再次拉取上游库映像以将其恢复到已知的干净状态:

And then pull the upstream library image again to revert it to a known clean state:

docker pull php:7.4-fpm

这篇关于docker-compose useradd 告诉我用户已经存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆