Build GitLab on Mac with Docker to simplify the installation process
1. Detailed installation steps
1. Install Docker
If you have not installed Docker, you can install it through the following steps:
- Download and installDocker Desktop for Mac.
- After the installation is complete, start Docker Desktop to ensure that Docker is running normally.
2. Pull the GitLab Docker image
GitLab officially provides a Docker image, which can be used directly to start a GitLab instance.
Open the terminal and run the following command to pull the GitLab image:
docker pull gitlab/gitlab-ce
3. Start the GitLab container
After pulling the image, you can start GitLab using the following command:
Create and start a GitLab container:
docker run -d --hostname --name gitlab \ -p 8080:80 -p 443:443 -p 22:22 \ -v /srv/gitlab/config:/etc/gitlab \ -v /srv/gitlab/logs:/var/log/gitlab \ -v /srv/gitlab/data:/var/opt/gitlab \ gitlab/gitlab-ce
explain:
-
--hostname
: Set the hostname for GitLab. -
-p 8080:80
: Expose GitLab's HTTP service to port 8080. -
-p 443:443
: Expose GitLab's HTTPS service to port 443. -
-p 22:22
: Expose GitLab's SSH service to port 22. -
-v /srv/gitlab/...
: These options map GitLab configuration, logs, and data stores to directories on the host system.
Wait for a few minutes and the GitLab container starts up.
4. Visit GitLab
Open the browser and accesshttp://localhost:8080
。
On the first visit, you need to set the password for the administrator account.
The default username isroot
, Password is the password you set on your first visit.
5. Configure GitLab (optional)
You can modify the configuration of GitLab as needed, such as adjusting ports, domain names, etc.
These configuration files are usually located in/srv/gitlab/config/
。
6. Start/stop GitLab service
- Start the GitLab container:
docker start gitlab
- Stop the GitLab container:
docker stop gitlab
7. Regular backup and restore
To prevent data loss, you can back up GitLab data regularly:
- Backup command:
docker exec -t gitlab gitlab-rake gitlab:backup:create
- Recovery command:
docker exec -t gitlab gitlab-rake gitlab:backup:restore BACKUP=timestamp_of_backup
Through the above steps, you can successfully build GitLab on your Mac.
If you need further configuration or encounter problems, you can check the official GitLab documentation or run it on the command linegitlab-ctl
To perform more management operations.
2. If the root and password are not matched, you can reset the password
If the full administrator password is not displayed when viewing the log, it may be because GitLab uses the mechanism for initial password generation, which should be automatically set on first startup.
If it is not displayed in the log, you can try the following method to get the administrator password:
1. Reset the administrator password directly
You can enter the container and manually reset the administrator password.
1.1 Enter the GitLab container
Execute the following command to enter the running GitLab container:
docker exec -it gitlab /bin/bash
1.2 Reset password using the GitLab Rails console
After entering the container, run the following command to start the GitLab Rails console:
gitlab-rails console
In the console, execute the following command to reset the administrator password:
user = (id: 1).first = 'your_new_password' user.password_confirmation = 'your_new_password' !
Will'your_new_password'
Replace with the new password you want to set.
1.3 Exit the console
After the setup is complete, exit the Rails console and container:
exit
2. Try the GitLab configuration file
If you haven't seen the password information before, you can try checking/etc/gitlab/
Whether the configuration file has an entry for the initial password.
If anything, you can view and change it manually.
3. Restart the container
After you have completed the password reset, you can restart the container to ensure the changes take effect:
docker restart gitlab
Then try to log in to the GitLab Web UI (http://localhost:8080
)
useroot
Log in with the new password you set
Summarize
Hope these steps can help you successfully obtain or reset your password!
The above is personal experience. I hope you can give you a reference and I hope you can support me more.