week 15.1 docker, in project IDX setUp

/*
  1. create and setup as mention on step1,2,3,4,5
//if you want to create your won docker project
    1) clone your prjoect or write your project
    2) Dockerfile //create a dockerfile in your root of project diricitory and write this inside your dockerfile. inside the Dockerfile mention all commands that will required before start you program. all snippet code mention bellow.
a) FROM node:22-alpine   #base image which will retrive by docker registry.
        a) FROM node:20   #base image which will retrive by docker registry.
b) WORKDIR /app     # working diricitory
c) COPY . .      #COPY OVER FILE
d) RUN npm install  #run command to build the program
d.1) RUN npm run build //
e) EXPOSE 8080      # EXPOSE PORT
#command to run the application
           f)   CMD ["node", "dist/index.js"
                                vs
f) CMD ["serve", "-s", "build"]
   
3)  .dockerignore //also make this file on your root of the project / similarity to with .gitignore file 
1) dist
2) node_modules
4) docker build -t [containerName] .   //this code will build the docker container

5)  docker run -p 27017:2717 -d [containerName]  //to run your container, dont forget to set your port number as your project mention
*/

+++++++++++++++++++++++++++++++++++++++++++

sudo usermod -aG docker $USER //this will change the docker group permission root user from normal user  
exec su -l $USER // after change the permission will refresh the terminal/shell

+++++++++++++++++++++++++++++++++++++++++++++++++

cut -d: -fi /etc/group | sort //this will show the all group in you system
sudo systemctl enable docker //This code enable automaticatily runnig when you onpen you system
sudo systemctl status docker //theis code is use to verify you docker is running or not
sudo systemctl start docker //if docker not start the use this code to run docker service

++++++++++++++++++++++++++++++++++++++++++++++++

some conman command

docker images ////show you all the images that you have on your machine.
docker ps -a // this will show you all your container with there pulling time.
docker ps //shows you all containers you are running on your machine.
docker run //let's you start a container
docker build //
docker run -p 27017:2717 -d mongo // to pull image of mongo images in his registry and run the mongo image. -d is use for command run detachable on terminal means internally terminal will free after running and -p is use for posrt maping.
docker init //to initialize a docker application
docker compose up --build //for run docker
docker kill [CONTAINER ID[1dde48b2c10f]] // to kill or stop the docker container ID
docker rmi monogo --force // to remove the image

 






### 1. Run a Simple Docker Container

To further test Docker, you can run a simple container, such as an Nginx web server:

```bash
docker run -d -p 8080:80 --name webserver nginx
```

This command will:
- Download the Nginx image from Docker Hub if it’s not already present.
- Run the Nginx container in detached mode (`-d`).
- Map port 8080 on your host to port 80 in the container (`-p 8080:80`).
- Name the container `webserver`.

You can verify it's running by accessing `http://localhost:8080` in your web browser. You should see the default Nginx welcome page.

### 2. List Running Containers

To see all running containers, use:

```bash
docker ps
```

To see all containers, including stopped ones, use:

```bash
docker ps -a
```

### 3. Stop and Remove Containers

To stop a running container:

```bash
docker stop webserver
```

To remove a stopped container:

```bash
docker rm webserver
```

To stop and remove in one command:

```bash
docker rm -f webserver
```

### 4. Build and Run Your ReactJS Project

Now that Docker is functioning properly, you can proceed to build and run your ReactJS project. Ensure you have a `Dockerfile` in your ReactJS project directory and follow these steps:

1. **Navigate to Your Project Directory:**

   ```bash
   cd /path/to/your/reactjs/project
   ```

2. **Build the Docker Image:**

   ```bash
   docker build -t my-react-app .
   ```

3. **Run the Docker Container:**

   ```bash
   docker run -d -p 8080:8080 --name reactapp my-react-app
   ```

### 5. Verify Your ReactJS Application

Access your ReactJS application by navigating to `http://localhost:8080` in your web browser. If your Dockerfile and project setup are correct, you should see your ReactJS application running.

### Summary

Here are the key commands you'll use for Docker with your ReactJS project:

- **Build your Docker image:**

  ```bash
  docker build -t my-react-app .
  ```

- **Run your Docker container:**

  ```bash
  docker run -d -p 8080:8080 --name reactapp my-react-app
  ```

- **Stop your Docker container:**

  ```bash
  docker stop reactapp
  ```

- **Remove your Docker container:**

  ```bash
  docker rm reactapp
  ```

These steps should help you ensure Docker is set up correctly and get your ReactJS project running in a Docker container.

docker exec -it [containerID] /bin/bash  //this command give you the access of the container in you terminal

=========================Porject IDX=========================

{pkgs}: {
channel = "stable-23.11";
packages = [
#pkgs.nodejs_20
];
env = {};
services.docker.enable = true;
idx.extensions = [
#"svelte.svelte-vscode"
#"vue.volar"
];
idx.previews = {
};
}

 **terminal**
 to build images or build your project use this code
code:-     docker build -t react-app:start .
 
1. [react-aap] is name you can use other name to your project docker image
2. [start] is define your command to start  you need to use keyword which start you app like:- start/dev
3. [ . ] dot is use to locate the file of the project
 
 
**run your project**

docker run  -d -p 3000:3000 [9d02cf90fcdf] ||docker run -d -p 3000:3000 [react-app:start]     if you use image-id on red bracket run directly
or if you use image name then define the keyword start your app e.g. {react-app:start} image name with keyword


Comments

Popular posts from this blog

CyberSecurity

VERTICAL SCALING 💋

prisma using in project idx 13.3