Update tech_docs/docker_dev_enviroments.md

This commit is contained in:
2024-06-02 03:21:51 +00:00
parent 63cffe7400
commit 839b525760

View File

@@ -1,3 +1,136 @@
Connecting tmux to your Docker containers' `bin/bash` terminal is a great way to manage and work with your codebase. Here's a step-by-step guide on how to set this up:
### Step 1: Install tmux on your host machine
If you haven't installed tmux on your host machine, you can do so with the following commands:
**On Ubuntu/Debian:**
```sh
sudo apt-get update
sudo apt-get install tmux
```
**On macOS:**
```sh
brew install tmux
```
### Step 2: Start a Docker container with interactive bash
You can start your Docker container with an interactive bash shell using the `-it` option:
```sh
docker run -it --name my-container my-image /bin/bash
```
Replace `my-container` with the name you want for your container and `my-image` with the name of your Docker image.
### Step 3: Attach tmux to the Docker container
Once you have your Docker container running, you can open a new tmux session on your host machine:
```sh
tmux new -s mysession
```
Replace `mysession` with the name you want for your tmux session.
### Step 4: Split tmux panes and attach to the container
In your tmux session, you can split the window into panes and attach each pane to the Docker container's bash shell.
**Horizontal Split:**
```sh
tmux split-window -h
```
**Vertical Split:**
```sh
tmux split-window -v
```
You can now attach each pane to the Docker container using the following command in each pane:
```sh
docker exec -it my-container /bin/bash
```
Replace `my-container` with the name of your running Docker container.
### Example Workflow
Heres an example workflow:
1. **Start tmux:**
```sh
tmux new -s devsession
```
2. **Start a Docker container:**
```sh
docker run -it --name json-processing-container json-processing-env /bin/bash
```
3. **Split tmux window:**
```sh
# Inside tmux, press Ctrl+b, then % for horizontal split
tmux split-window -h
# Or press Ctrl+b, then " for vertical split
tmux split-window -v
```
4. **Attach tmux panes to Docker container:**
```sh
# In the first pane
docker exec -it json-processing-container /bin/bash
# Move to the next pane (Ctrl+b, followed by the arrow key) and repeat
docker exec -it json-processing-container /bin/bash
```
### Step 5: Save tmux session for later use
You can save your tmux session setup and restore it later using a tmuxinator or tmux-resurrect plugin.
**Install tmuxinator:**
```sh
gem install tmuxinator
```
**Create a tmuxinator configuration:**
```sh
tmuxinator new myproject
```
Edit the generated `~/.tmuxinator/myproject.yml` configuration file to include your Docker container setup.
**Example `myproject.yml`:**
```yaml
name: myproject
root: ~/myproject
windows:
- editor:
layout: main-horizontal
panes:
- docker exec -it json-processing-container /bin/bash
- docker exec -it json-processing-container /bin/bash
- logs:
layout: even-vertical
panes:
- docker exec -it json-processing-container /bin/bash
- docker exec -it json-processing-container /bin/bash
```
**Start tmux session with tmuxinator:**
```sh
tmuxinator start myproject
```
This setup allows you to manage multiple Docker containers efficiently within tmux, keeping your development workflow organized and productive.
---
Certainly! Lets take a step back and define more logical and well-defined environments tailored to your needs. Well create distinct Docker environments for JSON processing, API interactions, notebook visualizations, data analysis, web development, DevOps, and testing. Certainly! Lets take a step back and define more logical and well-defined environments tailored to your needs. Well create distinct Docker environments for JSON processing, API interactions, notebook visualizations, data analysis, web development, DevOps, and testing.
### Logical Environments ### Logical Environments