Home Explore Blog CI



docker

5th chunk of `content/guides/named-entity-recognition.md`
b1fa4601e235bf880a5645662e989b47f49107bcd2b3a6b90000000100000cdb
     all the files and subdirectories in the specified directory.

   For more details, see the [docker build CLI reference](/reference/cli/docker/buildx/build/).

   Docker outputs several logs to your console as it builds the image. You'll
   see it download and install the dependencies. Depending on your network
   connection, this may take several minutes. Docker does have a caching
   feature, so subsequent builds can be faster. The console will
   return to the prompt when it's complete.

2. Run the image as a container.

   In a terminal, run the following command.

   ```console
   $ docker run -it basic-nlp 02_name_entity_recognition.py
   ```

   The following is a break down of the command:

   - `docker run`: This is the primary command used to run a new container from
     a Docker image.
   - `-it`: This is a combination of two options:
     - `-i` or `--interactive`: This keeps the standard input (STDIN) open even
       if not attached. It lets the container remain running in the
       foreground and be interactive.
     - `-t` or `--tty`: This allocates a pseudo-TTY, essentially simulating a
       terminal, like a command prompt or a shell. It's what lets you
       interact with the application inside the container.
   - `basic-nlp`: This specifies the name of the Docker image to use for
     creating the container. In this case, it's the image named `basic-nlp` that
     you created with the `docker build` command.
   - `02_name_entity_recognition.py`: This is the script you want to run inside
     the Docker container. It gets passed to the `entrypoint.sh` script, which
     runs it when the container starts.

   For more details, see the [docker run CLI reference](/reference/cli/docker/container/run/).

   > [!NOTE]
   >
   > For Windows users, you may get an error when running the container. Verify
   > that the line endings in the `entrypoint.sh` are `LF` (`\n`) and not `CRLF` (`\r\n`),
   > then rebuild the image. For more details, see [Avoid unexpected syntax errors, use Unix style line endings for files in containers](/desktop/troubleshoot-and-support/troubleshoot/topics/#Unexpected-syntax-errors-use-Unix-style-line endings-for-files-in-containers).

   You will see the following in your console after the container starts.

   ```console
   Enter the text for entity recognition (type 'exit' to end):
   ```

3. Test the application.

   Enter some information to get the named entity recognition.

   ```console
   Enter the text for entity recognition (type 'exit' to end): Apple Inc. is planning to open a new store in San Francisco. Tim Cook is the CEO of Apple.

   Entity: Apple Inc., Type: ORG
   Entity: San Francisco, Type: GPE
   Entity: Tim Cook, Type: PERSON
   Entity: Apple, Type: ORG
   ```

## Summary

This guide demonstrated how to build and run a named entity recognition
application. You learned how to build the application using Python with spaCy,
and then set up the environment and run the application using Docker.

Related information:

- [Docker CLI reference](/reference/cli/docker/)
- [Dockerfile reference](/reference/dockerfile/)
- [spaCy](https://spacy.io/)
- [Python documentation](https://docs.python.org/3/)

## Next steps

Explore more [natural language processing guides](./_index.md).

Title: Running and Testing the Named Entity Recognition Application in Docker
Summary
This section elaborates on running the Docker image as a container, detailing the `docker run` command and its options like `-it` (interactive TTY). It explains how to specify the image name and the script to run within the container. It also provides a note for Windows users regarding line endings in the `entrypoint.sh` file. The section then guides the user on testing the application by providing example input and expected output. Finally, the section summarizes the guide, listing related resources and suggests exploring more NLP guides.