---
# System prepended metadata

title: 'API: Configure api local environment with docker'

---

# API: Configure api local environment with docker

## Preparing local environment

**1. Download existing code**

```bash=
    git clone https://github.com/JaumeBalmesTFG/api.git
```
Make sure you have the correct credentials If is not ask me.

***

**2. Verify node version you must have (17.5.0). If you don't have it try to upgrade existing version or install node with brew (if you have macOS) or with apt (if you have liux)**

```bash=
    node --verison
```

***

**3. In the same directory install the necessary packages with the correct node version.**

``` bash=
    npm install --quite
```

If you have an error ask me.

***

**4. Then try to start on local server**

``` bash= 
    npm start
```

This will be able to acces at http://localhost:8080 If they show a welcome message you can continue with the next step. Remember close local server.

## Creating the docker

**1. Fist of all let's create docker image to do it we have to use the already existing dockerfile in the project.**

```bash=
    docker build -t api-image .
```
Make sure you are in the project folder.

Now let check if the image is succesfully created:

```bash=
    docker images
```
You must to see this image in the list. If si missing tell me.

![](https://i.imgur.com/4k8Tt3u.png)

***

**2. Create the container to do it execute the next command:**

```bash=
    docker run -d -p 8080:8080 -v /Users/xavigrausebastian/Documents/Project/API:/opt/app --name api-docker api-image
```

- **-d:** Background running
- **-p:** Port mapping
- **-v:** Volume mapping ${ABS_PATH_TO_PROJECT}:/opt/app
- **--name:** Container name
- **api-image:** Image created in the previews step

***

**3. Finally let's test, open http://localhost:8080 and they must be appere the same welcome message:**

![](https://i.imgur.com/L0r6aIW.png)

## See other documentation releted on the docker integration:

[Docker logs](https://hackmd.io/@tfg/Syx6NHdJ9)

[Docker controls](https://hackmd.io/@tfg/B1pWwruJ5)

