git init- Initialize a new Git repository.
git config --global user.name "Your Name"
git config --global user.email "[email protected]"- Set global configuration options.
git clone <repository_url>- Clone an existing repository.
git add <file_or_directory>
git add .- Stage changes for the next commit.
git commit -m "commit message"- Commit staged changes with a message.
git status- Show the working tree status.
git log- Show commit logs.
git branch
git branch <branch_name>
git checkout <branch_name>
git checkout -b <new_branch_name>- List branches, create a branch, switch to a branch, and create/switch to a new branch.
git merge <branch_name>- Merge changes from another branch into the current branch.
git remote add origin <remote_repository_url>
git push -u origin <branch_name>
git push- Add a remote repository, push changes to it, and push subsequent changes.
git pull- Fetch and integrate changes from the remote repository.
git stash
git stash pop- Save changes temporarily and retrieve them later.
git reset --hard <commit_hash>- Reset the working directory to a specific commit.
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- run: npm install
- run: npm test- Basic GitHub Actions workflow for CI.
stages:
- build
- test
build_job:
stage: build
script:
- echo "Building the project..."
test_job:
stage: test
script:
- echo "Running tests..."- Basic GitLab CI/CD pipeline example.
git remote add origin <repository_url>
git push -u origin master- Add a GitHub/GitLab repository and push initial commits.
- Create a new branch.
- Push the branch to the remote repository.
- Navigate to the repository on GitHub/GitLab.
- Open a Pull Request (GitHub) or Merge Request (GitLab).
- Navigate to repository settings on GitHub/GitLab.
- Add branch protection rules.
# Use an official Python runtime as a parent image
FROM python:3.8-slim-buster
# Set the working directory in the container
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Run app.py when the container launches
CMD ["python", "app.py"]- Basic Dockerfile example.
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
redis:
image: "redis:alpine"- Basic Docker Compose file example.
docker run -d -p 8080:80 -v /path/on/host:/path/in/container --name my_container my_image-d: Run the container in detached mode (in the background).-p 8080:80: Map port 8080 on the host to port 80 in the container. This means that requests tolocalhost:8080on your host will be forwarded to port 80 in the container.-v /path/on/host:/path/in/container: Mount a volume from the host to the container. The directory/path/on/hoston your host machine will be accessible inside the container at/path/in/container.--name my_container: Assign a name (my_container) to the container.my_image: The name of the Docker image to use.
You can adjust the port numbers, volume paths, container name, and image name according to your needs.
docker build -t myapp .- Build an image from a Dockerfile.
docker run -p 4000:80 myapp- Run a container and map ports.
docker ps
docker ps -a- List running containers and all containers.
docker stop <container_id>
docker rm <container_id>- Stop and remove containers.
docker images
docker rmi <image_id>- List and remove images.
docker-compose up
docker-compose down- Start and stop services defined in a Docker Compose file.
-
Make Changes to Your Code: Ensure you've saved all your changes to your code.
-
Use Docker Compose to Rebuild and Restart: Run the following command in the directory containing your
docker-compose.ymlfile:docker-compose up --build
This command tells Docker Compose to:
- Rebuild the images for the services defined in your
docker-compose.ymlfile. - Restart the containers with the updated images.
- Rebuild the images for the services defined in your
-
Remove Orphan Containers: If you have made changes that affect the service definitions (e.g., added or removed services), you might want to remove any orphaned containers:
docker-compose up --build --remove-orphans
-
Rebuilding Only Specific Services: If you only want to rebuild specific services, you can specify them:
docker-compose up --build service_name
-
Stopping and Removing Containers: If you want to ensure a clean state, you can stop and remove containers before rebuilding:
docker-compose down docker-compose up --build
-
Edit your code.
-
Rebuild and restart with Docker Compose:
docker-compose up --build