Question: I have a dilemma where I need to have a MySQL database create a customer number based on the first 3 characters of a new client name entered and to append an incremenenting value. For example:

**Table clients:**

```
+----+----------------------------------------------+--------------+
| id | clientName                                   | clientNumber |
+----+----------------------------------------------+--------------+
|  1 | Accelerated Learning                         | ACC00        |
|  2 | Acceleration Systems                         | ACC01        |
|  3 | Acme,Inc.                                    | ACM00        |

```

Normally I would do this in the submission form on the front end, but for reasons unexplained, the spec wants this handled by the DB. I'm trying to write something like this, but can't get it right:

**Trigger:**

```
CREATE DEFINER = CURRENT_USER TRIGGER `crmdev`.`clients_BEFORE_INSERT` BEFORE INSERT ON `clients` FOR EACH ROW
BEGIN
DECLARE prefix varchar(3);
DECLARE suffix INT(3);
SET prefix = SUBSTRING(NEW.clientName,1,3);
SET suffix = (
    SELECT COUNT(*),SUBSTRING(clientName,1,3) = prefix + 1;
SET NEW.clientNumber = CONCAT(prefix,suffix);
END

```

Thanks in advance for help/guidance!

Answer: 
As mentioned in the comments, a multi-stage build involves a single Dockerfile to perform multiple stages. What you have is a common base image.

You could convert these to a non-traditional multi-stage build with a syntax like (I say non-traditional because you do not perform any copying between the layers and instead use just the from line to pick from a prior stage):

```
FROM python:3.6 as base
RUN apt-get update && apt-get upgrade -y
RUN pip install pipenv pip
COPY Pipfile ./
# some more common configuration...

FROM base as dev
RUN pipenv install --system --skip-lock --dev
ENV FLASK_ENV development
ENV FLASK_DEBUG 1

FROM base as prod
RUN pipenv install --system --skip-lock
ENV FLASK_ENV production

```

Then you can build one stage or another using the `--target` syntax to build, or a compose file like:

```
# docker-compose.yml
version: '3.4'
services:
  webapp:
    build:
      context: ./dir
      dockerfile: Dockerfile
      target: prod

```

The biggest downside is the current build engine will go through every stage until it reaches the target. Build caching can mean that's only a sub-second process. And BuildKit which is coming out of experimental in 18.09 and will need upstream support from docker-compose will be more intelligent about only running the needed commands to get your desired target built.

All that said, I believe this is trying to fit a square peg in a round hole. The docker-compose developer is encouraging users to move away from doing the build within the compose file itself since it's not supported in swarm mode. Instead, the recommended solution is to perform builds with a CI/CD build server, and push those images to a registry. Then you can run the same compose file with `docker-compose` or `docker stack deploy` or even some k8s equivalents, without needing to redesign your workflow.
you can use as well concating of docker-compose files, with including both `dockerfile` pointing to your existing dockerfiles and run `docker-compose -f docker-compose.yml -f docker-compose.prod.yml build`